Author: dagolden
Date: Sat Sep 12 22:29:03 2009
New Revision: 13323
Modified:
Module-Build/branches/inc-bundling/lib/inc/latest.pm
Module-Build/branches/inc-bundling/t/bundle_inc.t
Log:
inc bundling of M::B appears to work
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
22:29:03 2009
@@ -3,10 +3,11 @@
use warnings;
use Carp;
-use File::Spec;
-use File::Basename;
-use File::Path;
-use IO::File;
+use File::Basename ();
+use File::Spec ();
+use File::Path ();
+use IO::File ();
+use File::Copy ();
sub import {
my ($package, $mod, @args) = @_;
@@ -47,14 +48,47 @@
my ($where) = @_;
warn "should really be writing in inc/" unless $where =~ /inc$/;
- mkpath $where;
+ File::Path::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) = @_;
+
+ # create inc/inc_$foo
+ (my $dist = $module) =~ s{::}{-}g;
+ my $inc_lib = File::Spec->catdir($where,"inc_$dist");
+ File::Path::mkpath $inc_lib;
+
+ # get list of files to copy
+ require ExtUtils::Installed;
+ my $inst = ExtUtils::Installed->new;
+ my @files = $inst->files( $module, 'prog' );
+
+ # figure out prefix
+ my $mod_path = quotemeta $package->_mod2path( $module );
+ my ($prefix) = grep { /$mod_path$/ } @files;
+ $prefix =~ s{$mod_path$}{};
+
+ # copy files
+ for my $from ( @files ) {
+ next unless $from =~ /\.pm$/;
+ (my $mod_path = $from) =~ s{^\Q$prefix\E}{};
+ my $to = File::Spec->catfile( $inc_lib, $mod_path );
+ File::Path::mkpath(File::Basename::dirname($to));
+ File::Copy::copy( $from, $to ) or die "Couldn't copy '$from' to '$to': $!";
+ }
+ return 1;
+}
+# Translate a module name into a directory/file.pm to search for in @INC
+sub _mod2path {
+ my ($self, $mod) = @_;
+ my @parts = split /::/, $mod;
+ $parts[-1] .= '.pm';
+ return $parts[0] if @parts == 1;
+ return File::Spec->catfile(@parts);
}
1;
Modified: Module-Build/branches/inc-bundling/t/bundle_inc.t
==============================================================================
--- Module-Build/branches/inc-bundling/t/bundle_inc.t (original)
+++ Module-Build/branches/inc-bundling/t/bundle_inc.t Sat Sep 12 22:29:03 2009
@@ -6,7 +6,7 @@
use DistGen;
use File::Spec;
-plan tests => 5;
+plan tests => 7;
# Ensure any Module::Build modules are loaded from correct directory
blib_load('Module::Build');
@@ -34,4 +34,13 @@
"./inc/inc_Module_Build created"
);
+ok( -e File::Spec->catfile( $dist_inc, qw/inc_Module-Build Module Build.pm/ ),
+ "./inc/inc_Module_Build/Module/Build.pm created"
+);
+
+ok( -e File::Spec->catfile( $dist_inc, qw/inc_Module-Build Module Build
Base.pm/ ),
+ "./inc/inc_Module_Build/Module/Build/Base.pm created"
+);
+
+
# vim:ts=2:sw=2:et:sta:sts=2