Subject: | Correct deployment of bundled modules |
Hi,
Included is a patch against Module::Install SVN revision 11928.
It affects only file Module/Install/Bundle.pm. The first time a user
deploys a package that has bundled modules (be it with auto_bundle_deps,
bundle_deps, auto_bundle, or bundle), the bundled modules (read from
inc/BUNDLE.yml) are added to the list of modules to process for
installation. Also, I added a checks to make sure that the directory
where a bundled module lives is valid.
Cheers,
Florent
Subject: | bundle.diff |
Index: Bundle.pm
===================================================================
--- Bundle.pm (revision 11928)
+++ Bundle.pm (working copy)
@@ -35,6 +35,19 @@
my $bundle_dir = $self->_top->{bundle};
$bundle_dir =~ s/\W+/\\W+/g;
+ # The first time here as a user, process all modules bundled
+ if ( (scalar keys %$bundles > 0) && (not $self->{_bundle_processed}) ) {
+ while ( my ($mod_name, $dist_source_dir) = each %{$bundles} ) {
+ my $version = 0;
+ if ($dist_source_dir =~ m/^$bundle_dir\W+.*-(.+?)$/i) {
+ $version = $1;
+ }
+ # Prepend bundled modules to list of modules to process
+ unshift @_, $mod_name, $version;
+ }
+ $self->{_bundle_processed} = 1;
+ }
+
while (my ($mod_name, $version) = splice(@_, 0, 2)) {
$version ||= 0;
@@ -51,16 +64,22 @@
# Move distribution to package root for deployment by make
my $dist_target_dir = File::Basename::basename($dist_source_dir);
- mkdir( $dist_target_dir, 0777 ) or die $! unless -d $dist_target_dir;
- File::Find::find({
- wanted => sub {
- my $out = $_;
- $out =~ s/$bundle_dir/./i;
- mkdir( $out, 0777 ) if -d;
- File::Copy::copy($_ => $out) unless -d;
- },
- no_chdir => 1,
- }, $dist_source_dir);
+ if (not -d $dist_target_dir) {
+ if (not -d $dist_source_dir) {
+ warn "Warning: Cannot find expected dir $dist_source_dir\n";
+ next;
+ }
+ mkdir( $dist_target_dir, 0777 ) or die $!;
+ File::Find::find({
+ wanted => sub {
+ my $out = $_;
+ $out =~ s/$bundle_dir/./i;
+ mkdir( $out, 0777 ) if -d;
+ File::Copy::copy($_ => $out) unless -d;
+ },
+ no_chdir => 1,
+ }, $dist_source_dir);
+ }
# Delete this build directory upon "make clean"
$self->clean_files( $dist_target_dir );
@@ -102,20 +121,22 @@
my @core = map @$_, map @$_, grep ref, $self->requires;
while (my ($name, $version) = splice(@core, 0, 2)) {
next unless $name;
- $self->bundle_deps($name, $version);
+ $self->bundle_deps($name, $version);
}
}
sub bundle_deps {
my ($self, $pkg, $version) = @_;
my $deps = $self->admin->scan_dependencies($pkg);
- if (scalar keys %$deps == 0) {
- # Probably a user trying to install the package, read the dependencies from META.yml
- %$deps = ( map { $$_[0] => undef } (@{$self->requires()}) );
+ if ($deps) {
+ # Bundle the dependencies found by the admin
+ foreach my $key (sort keys %$deps) {
+ $self->bundle($key, ($key eq $pkg) ? $version : 0);
+ }
+ } else {
+ # Users process the bundled dependencies
+ $self->bundle();
}
- foreach my $key (sort keys %$deps) {
- $self->bundle($key, ($key eq $pkg) ? $version : 0);
- }
}
1;