#!/usr/bin/perl -w use strict; use Drupal::Module::Starter; use YAML; use Getopt::Long; use Pod::Usage; use POSIX qw/tmpnam/; =head1 NAME drupal-module-starter - creates a skeleton Drupal module distribution =cut my $config; pod2usage(2) unless @ARGV; =head1 SYNOPSIS drupal-module-starter [options] Options: --module=your_module_name Module name (required, repeatable) --dir Directory name to create new module in (optional) --author=name Author's name (required) --email=email Author's email (required) --hooks=list,of,hooks,here Which hooks you wish to generate stubs for --verbose Print progress messages while working --force Delete pre-existing files if needed --help Show this message Example: drupal-module-starter --module=Recording,Artist,Track,Discography,Review,PodCastGenerator,Pony \ --author="Steve McNabb" --email="smcnabb@cpan.org" \ --dir=/tmp/someone/projects/drupal/dev --hooks=xmlrpc,form,help,info,init,insert,delete,update This would create the 7 listed modules, each in its own directory under --dir, with stubs installed for the listed --hooks (if any). hook_name and hook_perm are always generated.s =cut GetOptions( "module=s" => ($config->{modules} ||= []), "dir=s" => \$config->{dir}, "email=s" => \$config->{email}, "author=s" => \$config->{author}, "hooks=s" => ($config->{hooks} ||= []) , "verbose=s" => \$config->{verbose}, "force=s" => \$config->{force}, ); # set defaults if(!$config->{dir}) { $config->{dir} = '.' } if(!$config->{modules}[0]) { die "No --module(s) passed to $0"; } if(!$config->{author}) { die "No --author set - the --author option is required" } if(!$config->{email}) { die "No --email set - the --email option is required" } if(!$config->{hooks}) { warn "No hooks defined - reverting to default hooks (perm and node_name)" } # run file generation my @modules = split /,/, $config->{modules}[0]; foreach my $module (@modules) { print "make module $module in $config->{dir}\n"; no warnings 'uninitialized'; # write a YAML file to pass to Drupal::Module::Starter my $tmpfile = POSIX::tmpnam(); my $yaml = Drupal::Module::Starter::sample_yaml(); $yaml .= "module: $module\n"; $yaml .= "author: $config->{author}\n"; $yaml .= "email: $config->{email}\n"; $yaml .= "dir: $config->{dir}\n"; $yaml .= "force: $config->{force}\n" if $config->{force}; # set up hooks my @hooks = split /,/, $config->{hooks}[0]; for my $hook (@hooks) { $yaml =~ s/hook_$hook:\s+\d+?/hook_$hook: 1/; } open(TMPFILE, ">$tmpfile") or die "Couldn't open $tmpfile for write.."; print TMPFILE $yaml; close TMPFILE; # create a Starter object my $module = Drupal::Module::Starter->new($tmpfile); # run the generation $module->generate; # clean up the tempfile unlink($tmpfile); } =head1 AUTHOR Steve McNabb, C<< >> IT Director, F5 Site Design - http://www.f5sitedesign.com Open Source Internet Application Development 1;