http://qs321.pair.com?node_id=11107834


in reply to TIMTOWTDI but how do you use Perl to create CLI scripts?

I'm a bit late to the discussion, but here's my general train of thought:

I'm all for code re-use, but just as I don't optimize prematurely, I also don't code for nonexistent future requirements prematurely. So if there is no foreseeable reason to want to re-use the code, I just get on with writing the script. If there is a possible future reason to re-use the code, I'll still just write the script.

Whenever I have a little downtime, I'll go through my ~/bin (which is part of my source code tracked with CVS, and now git, that follows me everywhere), and look for candidates for re-use. I hardly ever find anything, yet I keep adding scripts that I use regularly. When I know something'll get re-used, then I'll break that out into a module.

I don't use any of the App::*-type modules, but that's mainly because I've never found any that were a good fit for me. I'm watching this thread for suggestions, though.

Most of my "personal use" scripts start like this:

use Local::Stuff; # See below my %o = ( help => sub { pod2usage( -verbose => 2 ) }, # ... defaults go here ... ); GetOptions(\%o, qw< help option=s other=i >) or pod2usage(); __END__ =head1 POD Documentation

What is Local::Stuff?

Local::Stuff is a convenience module I wrote. It stays local to my systems, as the name suggests. It uses Import::Into to hack the caller's namespace to enable pragmas like strict, warnings, and autodie, as well as pull in modules I use frequently and import a few helper subs. All of its features are configurable, but I rarely have to do so. Finally, it's actually spelled Local::Shit to dissuade myself from using it in client code. (Edited to clarify Local::Stuff is not a public dist.)

what are the best, most efficient practices for creating a cool library of perl commands to help you get work done faster?

Use something like Module::Starter to create a skeleton for your new module, then add your cool library code to lib/Local/Cool.pm, write some unit tests in t/, and now you have a module that can be installed easily on anything that runs Perl. See perlnewmod for more info.

As for scripts, you already have the right idea. Just throw them in ~/bin (and use some kind of version control like git).