summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTatsuhiko Miyagawa <miyagawa@bulknews.net>2013-08-10 21:15:11 -0700
committerTatsuhiko Miyagawa <miyagawa@bulknews.net>2013-08-10 21:15:11 -0700
commit520305ad21e6a48753a9748a594296136ce7a99f (patch)
tree5c229d5450581c751c95a655aa5336478638b918
parent658541b4ad74686a22f834dd8ade4e2482907d78 (diff)
downloadcarton-520305ad21e6a48753a9748a594296136ce7a99f.tar.gz
Load extra modules for fatpack, detected from Carton's MYMETA files
-rw-r--r--lib/Carton/Packer.pm59
1 files changed, 52 insertions, 7 deletions
diff --git a/lib/Carton/Packer.pm b/lib/Carton/Packer.pm
index 9d604b6..e261be2 100644
--- a/lib/Carton/Packer.pm
+++ b/lib/Carton/Packer.pm
@@ -3,6 +3,8 @@ use strict;
use App::FatPacker;
use File::pushd ();
use Path::Tiny ();
+use CPAN::Meta ();
+use File::Find ();
use Moo;
@@ -23,10 +25,22 @@ $Carton::Fatpacked = 1;
exit Carton::CLI->new->run(@ARGV);
EOF
- my $packer = App::FatPacker->new;
+ my $fatpacked = $self->do_fatpack($file);
+
+ my $executable = $dir->child('carton');
+ warn "Bundling $executable\n";
+
+ $dir->mkpath;
+ $executable->spew($fatpacked);
+ chmod 0755, $executable;
+}
- my @modules = split /\r?\n/, $packer->trace(args => [$file], use => ['App::cpanminus']);
+sub do_fatpack {
+ my($self, $file) = @_;
+
+ my $packer = App::FatPacker->new;
+ my @modules = split /\r?\n/, $packer->trace(args => [$file], use => $self->required_modules);
my @packlists = $packer->packlists_containing(\@modules);
$packer->packlists_to_tree(Path::Tiny->new('fatlib')->absolute, \@packlists);
@@ -39,12 +53,43 @@ EOF
use Config;
$fatpacked =~ s/\$fatpacked{"$Config{archname}\/(Cwd|File)/\$fatpacked{"$1/g;
- my $executable = $dir->child('carton');
- warn "Bundling $executable\n";
+ $fatpacked;
+}
- $dir->mkpath;
- $executable->spew($fatpacked);
- chmod 0755, $executable;
+sub required_modules {
+ my($self, $packer) = @_;
+
+ my $meta = $self->installed_meta('Carton')
+ or die "Couldn't find install metadata for Carton";
+
+ my %excludes = (
+ perl => 1,
+ 'ExtUtils::MakeMaker' => 1,
+ 'Module::Build' => 1,
+ );
+
+ my @requirements = grep !$excludes{$_},
+ $meta->effective_prereqs->requirements_for('runtime', 'requires')->required_modules;
+
+ return \@requirements;
+}
+
+sub installed_meta {
+ my($self, $dist) = @_;
+
+ my @meta;
+ my $finder = sub {
+ if (m!\b$dist-.*[\\/]MYMETA.json!) {
+ push @meta, CPAN::Meta->load_file($_);
+ }
+ };
+
+ File::Find::find({ wanted => $finder, no_chdir => 1 }, grep -d, map "$_/.meta", @INC);
+
+ # return the latest version
+ @meta = sort { version->new($b->version) cmp version->new($a->version) } @meta;
+
+ return $meta[0];
}
1;