Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

Re: Best Module Starter?

by brian_d_foy (Abbot)
on Nov 09, 2007 at 04:27 UTC ( #649856=note: print w/ replies, xml ) Need Help??


in reply to Best Module Starter?

This is the topic of one of my TPJ columns: Making New Distributions.

I use Template Toolkit. I create a directory of templates that do exactly what I want then process it with ttree. I can make the templates any way that I like without fooling with someone else's idea of what they should be, and my template cooker script can set any variables it likes so I don't have to specify those with the command.

I've made it even easier since I wrote that article. I use it this like:

prompt> module_cooker Foo::Bar

Here's the code:

#!/usr/bin/perl use Cwd; use File::Spec; my $module = $ARGV[0] || prompt( "Module name> " ); my $dist = $module; $dist =~ s/::/-/g; my $file = $module; $file =~ s/.*:://; $file .= ".pm"; my $cwd = File::Spec->catfile( cwd(), $dist ); system join " ", "/usr/local/bin/ttree" , "-s ~/.templates/modules" , "-d $cwd" , "-define module='$module'" , "-define module_file='$file'" , "-define module_dist='$dist'" ; chdir $dist; ( my $base = $module ) =~ s/.*:://; rename File::Spec->catfile( 'lib', 'Foo.pm' ), File::Spec->catfile( 'lib', $file ); sub prompt { print join "\n", @_; print "> "; my $line = <STDIN>; chomp $line; $line; }
--
brian d foy <brian@stonehenge.com>
Subscribe to The Perl Review


Comment on Re: Best Module Starter?
Select or Download Code
Re^2: Best Module Starter?
by dynamo (Chaplain) on Nov 09, 2007 at 04:52 UTC
    Thank you, this is a lot of good info to digest. I'm still considering how the rest of the template directory would look, as I'm a little rusty on my Template::Toolkit, but in the meantime, the article looks like a good start.

    Update - I like the approach, and in the long term I might want to adopt something similar myself, but at this point I don't have that template directory of exactly how I like everything.
Re^2: Best Module Starter?
by Monk::Thomas (Beadle) on Jun 20, 2013 at 09:46 UTC
    Thanks for the script. I changed it a bit. Here's my version. (Hopefully I didn't introduce a bug.)
    #!/usr/bin/perl # # a simple module initializer using TemplateToolkit # original source: http://www.perlmonks.org/?node_id=649856 # - code rewritten a bit # - use Path::Class instead of File::Spec # - renamed 'Foo.pm' template file to Module.pm use Cwd; use Path::Class qw(file); my $template_dir = "~/.templates/modules/"; my $module = $ARGV[0] || prompt( "Module name> " ); (my $dist = $module) =~ s/::/-/g; # Foo::Bar::Baz -> Foo-Bar-Baz (my $base = $module) =~ s/.*:://; # Foo::Bar::Baz -> Baz my $file = $base . ".pm"; # Baz -> Baz.pm my $cwd = file(cwd(), $dist); # must contain ttree (provided through Template Toolkit) $ENV{PATH} = '/usr/local/bin:/usr/bin:/bin'; my @command = ( 'ttree', "-s $template_dir", "-d $cwd", "-define module='$module'", "-define module_file='$file'", "-define module_dist='$dist'", ); system join " ", @command; chdir $dist; rename file('lib', 'Module.pm'), file('lib', $file); sub prompt { print join "\n", @_; print "> "; my $line = <STDIN>; chomp $line; $line; }

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://649856]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others wandering the Monastery: (9)
As of 2014-08-01 05:04 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite superfluous repetitious redundant duplicative phrase is:









    Results (256 votes), past polls