Author: dagolden
Date: Sat Sep 12 21:42:23 2009
New Revision: 13321
Added:
Module-Build/branches/inc-bundling/t/bundle_inc.t (contents, props changed)
Modified:
Module-Build/branches/inc-bundling/Build.PL
Module-Build/branches/inc-bundling/lib/Module/Build/Base.pm
Module-Build/branches/inc-bundling/lib/inc/latest.pm
Module-Build/branches/inc-bundling/t/lib/DistGen.pm
Log:
first steps: flag modules to bundle; write inc/latest.pm
Modified: Module-Build/branches/inc-bundling/Build.PL
==============================================================================
--- Module-Build/branches/inc-bundling/Build.PL (original)
+++ Module-Build/branches/inc-bundling/Build.PL Sat Sep 12 21:42:23 2009
@@ -35,6 +35,7 @@
'File::Path' => 0,
'File::Spec' => ($^O eq 'MSWin32' ? 3.30 : '0.82'), # rel2abs()
'ExtUtils::Install' => 0,
+ 'ExtUtils::Installed' => 0,
'ExtUtils::Manifest' => 0,
'ExtUtils::Mkbootstrap' => 0,
'IO::File' => 0,
Modified: Module-Build/branches/inc-bundling/lib/Module/Build/Base.pm
==============================================================================
--- Module-Build/branches/inc-bundling/lib/Module/Build/Base.pm (original)
+++ Module-Build/branches/inc-bundling/lib/Module/Build/Base.pm Sat Sep 12
21:42:23 2009
@@ -52,6 +52,8 @@
}
}
+ $self->check_bundling;
+
$self->dist_name;
$self->dist_version;
@@ -839,6 +841,7 @@
__PACKAGE__->add_property(build_elements => [qw(PL support pm xs share_dir pod
script)]);
__PACKAGE__->add_property(build_script => 'Build');
__PACKAGE__->add_property(build_bat => 0);
+__PACKAGE__->add_property(bundle_inc => []);
__PACKAGE__->add_property(config_dir => '_build');
__PACKAGE__->add_property(include_dirs => []);
__PACKAGE__->add_property(license => 'unknown');
@@ -1164,6 +1167,45 @@
$self->{phash}{$_}->write() foreach qw(notes cleanup features auto_features
config_data runtime_params);
}
+{
+ # packfile map -- keys are guts of regular expressions; If they match,
+ # values are module names corresponding to the packlist
+ my %packlist_map = (
+ '^File::Spec' => 'Cwd'
+ );
+
+ sub check_bundling {
+ my $self = shift;
+ my $bundle_inc = $self->{properties}{bundle_inc};
+ # We're in author mode if inc::latest is loaded, but not from cwd
+ return unless $INC{'inc/latest.pm'} && ! -e 'inc/latest.pm';
+ require ExtUtils::Installed;
+ my $inst = ExtUtils::Installed->new;
+ for my $mod ( inc::latest->loaded_modules ) {
+ my $lookup = $mod;
+ my $packlist = eval { $inst->packlist($lookup) };
+ if ( ! $packlist ) {
+ # try from packlist_map
+ while ( my ($re, $new_mod) = each %packlist_map ) {
+ if ( $mod =~ qr/$re/ ) {
+ $lookup = $new_mod;
+ $packlist = eval { $inst->packlist($lookup) };
+ last;
+ }
+ }
+ }
+ if ( ! $packlist ) {
+ # XXX Really needs a more helpful error message here
+ die << "NO_PACKLIST";
+Could not find a packlist for '$mod'. If it's a core module, try
+force installing it from CPAN.
+NO_PACKLIST
+ }
+ push @$bundle_inc, $lookup;
+ }
+ } # sub check_bundling
+}
+
sub check_autofeatures {
my ($self) = @_;
my $features = $self->auto_features;
@@ -3525,6 +3567,15 @@
}
}
+sub do_create_bundle_inc {
+ my $self = shift;
+ my $dist_inc = File::Spec->catdir( $self->dist_dir, 'inc' );
+ require inc::latest;
+ inc::latest->write($dist_inc);
+ inc::latest->bundle_module($_, $dist_inc) for @{$self->bundle_inc};
+ return 1;
+}
+
sub ACTION_distdir {
my ($self) = @_;
@@ -3551,6 +3602,8 @@
my $new = $self->copy_if_modified(from => $file, to_dir => $dist_dir,
verbose => 0);
}
+ $self->do_create_bundle_inc if $self->bundle_inc;
+
$self->_sign_dir($dist_dir) if $self->{properties}{sign};
}
Modified: Module-Build/branches/inc-bundling/lib/inc/latest.pm
==============================================================================
--- Module-Build/branches/inc-bundling/lib/inc/latest.pm (original)
+++ Module-Build/branches/inc-bundling/lib/inc/latest.pm Sat Sep 12
21:42:23 2009
@@ -46,13 +46,17 @@
my $package = shift;
my ($where) = @_;
- my $dir = dirname( $where );
- warn "should really be writing in inc/" unless $dir =~ /inc$/;
- mkpath $dir;
- my $fh = IO::File->new( $where, "w" );
+ warn "should really be writing in inc/" unless $where =~ /inc$/;
+ mkpath $where;
+ my $fh = IO::File->new( File::Spec->catfile($where,'latest.pm'), "w" );
print {$fh} do {local $/; <DATA>};
}
+sub bundle_module {
+ my ($package, $module, $where) = @_;
+
+}
+
1;
__DATA__
Added: Module-Build/branches/inc-bundling/t/bundle_inc.t
==============================================================================
--- (empty file)
+++ Module-Build/branches/inc-bundling/t/bundle_inc.t Sat Sep 12 21:42:23 2009
@@ -0,0 +1,37 @@
+# sample.t -- a sample test file for Module::Build
+
+use strict;
+use lib $ENV{PERL_CORE} ? '../lib/Module/Build/t/lib' : 't/lib';
+use MBTest; # or 'no_plan'
+use DistGen;
+use File::Spec;
+
+plan tests => 5;
+
+# Ensure any Module::Build modules are loaded from correct directory
+blib_load('Module::Build');
+
+# create dist object in a temp directory
+# enter the directory and generate the skeleton files
+my $dist = DistGen->new( inc => 1 )->chdir_in->regen;
+
+# get a Module::Build object and test with it
+my $mb = $dist->new_from_context(); # quiet by default
+isa_ok( $mb, "Module::Build" );
+is( $mb->dist_name, "Simple", "dist_name is 'Simple'" );
+is_deeply( $mb->bundle_inc, [ 'Module::Build' ],
+ "Module::Build is flagged for bundling"
+);
+
+# see what gets bundled
+my $dist_inc = File::Spec->catdir($mb->dist_dir, 'inc');
+stdout_stderr_of( sub { $mb->dispatch('distdir') } );
+ok( -e File::Spec->catfile( $dist_inc, 'latest.pm' ),
+ "./inc/latest.pm created"
+);
+
+ok( -d File::Spec->catdir( $dist_inc, 'inc_Module-Build' ),
+ "./inc/inc_Module_Build created"
+);
+
+# vim:ts=2:sw=2:et:sta:sts=2
Modified: Module-Build/branches/inc-bundling/t/lib/DistGen.pm
==============================================================================
--- Module-Build/branches/inc-bundling/t/lib/DistGen.pm (original)
+++ Module-Build/branches/inc-bundling/t/lib/DistGen.pm Sat Sep 12 21:42:23 2009
@@ -91,6 +91,7 @@
my %data = (
no_manifest => 0,
xs => 0,
+ inc => 0,
%options,
);
%$self = %data;
@@ -143,17 +144,32 @@
$self->add_file($member, $data) unless($self->{filedata}{$member});
};
- $self->$add_unless('Build.PL', undent(<<" ---"));
- use strict;
- use Module::Build;
+ if ( ! $self->{inc} ) {
+ $self->$add_unless('Build.PL', undent(<<" ---"));
+ use strict;
+ use Module::Build;
- my \$builder = Module::Build->new(
- module_name => '$self->{name}',
- license => 'perl',
- );
+ my \$builder = Module::Build->new(
+ module_name => '$self->{name}',
+ license => 'perl',
+ );
- \$builder->create_build_script();
- ---
+ \$builder->create_build_script();
+ ---
+ }
+ else {
+ $self->$add_unless('Build.PL', undent(<<" ---"));
+ use strict;
+ use inc::latest 'Module::Build';
+
+ my \$builder = Module::Build->new(
+ module_name => '$self->{name}',
+ license => 'perl',
+ );
+
+ \$builder->create_build_script();
+ ---
+ }
my $module_filename =
join( '/', ('lib', split(/::/, $self->{name})) ) . '.pm';