Date: | Mon, 05 Apr 2004 19:59:21 -0400 |
From: | "Randy W. Sims" <ml-perl [...] thepierianspring.org> |
To: | Andy Lester <andy [...] petdance.com> |
CC: | module-authors [...] perl.org, module-build-general [...] lists.sourceforge.net, Ken Williams <ken [...] mathforum.org> |
Subject: | Re: Module::Starter released |
Andy Lester wrote:
Show quoted text
> I've just released Module::Starter 0.02, meant as a replacement for h2xs.
>
> I think h2xs is very out of date as far as current best practices for
> modules. It's also very intimidating for people who just want to create
> a module, and have no need for all the compiler hoohah that h2xs throws
> at you. Module::Starter is meant to make things much eaiser.
Attached is a patch with preliminary support for Module::Build support.
I added a 'builder' option for specifing whether to use M::B or
MakeMaker; default is still MakeMaker. I also added a 'license' option
as M::B likes to have it and the next version of MakeMaker will also
support it (for META.yml) although it is not in the current snapshot.
One thing that may be desirable is to add options for Build.PL and
Makefile.PL to co-exist, using one of Module::Build's compatability modes.
Another addition would be to allow module-starter to write a module for
an already created project. For example, if you create a project
'module-starter --module='Foo::Bar'', and later, you decide you need
another module to add to the existing project. 'module-starter
--module-only --module='Foo::Bar::Baz''.
Randy.
diff -urN Module-Starter-0.02-orig/Starter.pm Module-Starter-0.02/Starter.pm
--- Module-Starter-0.02-orig/Starter.pm Sun Apr 4 23:32:12 2004
+++ Module-Starter-0.02/Starter.pm Mon Apr 5 19:44:32 2004
@@ -45,12 +45,15 @@
=item * $email
+=item * $license
+
=back
=cut
our $verbose = 0;
our $force = 0;
+our $license = undef;
our $author = "Module Author";
our $email = "i-have-no-email\@example.com";
@@ -63,6 +66,7 @@
dir => $dirname,
modules => [ module names ],
distro => $distroname,
+ builder => 'Module::Build', # Defaults to ExtUtils::MakeMaker
=cut
@@ -78,6 +82,10 @@
die "Must specify an author\n" unless $author;
die "Must specify an email address\n" unless $email;
+ unless ( defined($license) ) {
+ warn "Defaulting to 'perl' license type\n";
+ $license = 'perl';
+ }
my $distro = $args{distro};
if ( not defined $distro ) {
@@ -93,7 +101,13 @@
push @files, create_t( $basedir, @modules );
push @files, create_cvsignore( $basedir, $distro );
- push @files, create_Makefile_PL( $basedir, $distro, $modules[0] );
+
+ if ( $args{builder} eq 'Module::Build' ) {
+ push @files, create_Build_PL( $basedir, $distro, $modules[0] );
+ } else {
+ push @files, create_Makefile_PL( $basedir, $distro, $modules[0] );
+ }
+
push @files, create_Changes( $basedir, $distro );
push @files, "MANIFEST";
push @files, 'META.yml # Will be created by "make dist"';
@@ -172,7 +186,7 @@
my $module_file = File::Spec->catfile( @dirparts, $filepart );
open( my $fh, ">", $module_file ) or die "Can't create $module_file: $!\n";
- print $fh _module_guts( $module );
+ print $fh &_module_guts( $module );
close $fh;
print "Created $module_file\n" if $verbose;
@@ -301,6 +315,49 @@
print "Created $fname\n" if $verbose;
return "Makefile.PL";
+}
+
+=head2 create_Build_PL( $basedir, $distro, $main_module )
+
+Creates a Build.PL for the given module distro.
+
+=cut
+
+sub create_Build_PL {
+ my $basedir = shift;
+ my $distro = shift;
+ my $main_module = shift;
+
+ my @parts = split( /::/, $main_module );
+ my $pm = pop @parts;
+ my $main_pm_file = File::Spec->catfile( "lib", @parts, "${pm}.pm" );
+
+ my $fname = File::Spec->catfile( $basedir, "Build.PL" );
+ open( my $fh, ">", $fname ) or die "Can't create $fname: $!\n";
+
+print $fh <<"HERE";
+use strict;
+use warnings;
+use Module::Build;
+
+my \$builder = Module::Build->new(
+ module_name => '$main_module',
+ license => '$license',
+ dist_author => '$author <$email>',
+ dist_version_from => '$main_pm_file',
+ requires => {
+ 'Test::More' => 0,
+ },
+ add_to_cleanup => [ '$distro-*' ],
+);
+
+\$builder->create_build_script();
+HERE
+
+ close $fh;
+ print "Created $fname\n" if $verbose;
+
+ return "Build.PL";
}
=head2 create_Changes( $basedir, $distro )
diff -urN Module-Starter-0.02-orig/bin/module-starter Module-Starter-0.02/bin/module-starter
--- Module-Starter-0.02-orig/bin/module-starter Sun Apr 4 23:17:02 2004
+++ Module-Starter-0.02/bin/module-starter Mon Apr 5 19:41:07 2004
@@ -15,21 +15,29 @@
my $distro;
my $dir;
+my $builder = 'ExtUtils::MakeMaker';
+
GetOptions(
"distro=s" => \$distro,
"module=s" => \@modules,
+ "builder=s" => \$builder,
"author=s" => \$Module::Starter::author,
"email=s" => \$Module::Starter::email,
+ "license=s" => \$Module::Starter::license,
force => \$Module::Starter::force,
verbose => \$Module::Starter::verbose,
version => sub { print "module-starter v$Module::Starter::VERSION\n"; exit 1; },
help => sub { pod2usage(1); },
) or pod2usage(2);
+pod2usage(2) unless ( $builder eq 'ExtUtils::MakeMaker' ||
+ $builder eq 'Module::Build' );
+
create_distro(
distro => $distro,
modules => [@modules],
+ builder => $builder,
);
@@ -39,14 +47,19 @@
Options:
- --module=module Module name (repeatable)
- --distro=name Distribution name (optional)
- --dir Directory name to create new module in (optional)
+ --module=module Module name (repeatable)
+ --distro=name Distribution name (optional)
+ --dir Directory name to create new module in (optional)
+
+ --builder=module Build with 'ExtUtils::MakeMaker' or 'Module::Build'
+
+ --author=name Author's name (required)
+ --email=email Author's email (required)
- --author=name Author's name (required)
- --email=email Author's email (required)
+ --license=type License under which the module will be distributed
+ (default is the same license as perl)
- --help Show this message
+ --help Show this message
Example: