Permalink
Browse files

Support cpanfile!

  • Loading branch information...
1 parent 8151aeb commit 03ead7bf8f5d16ce9c22e877ff8409ce5532c350 @miyagawa miyagawa committed Apr 12, 2012
Showing with 25 additions and 27 deletions.
  1. +12 −8 lib/Carton.pm
  2. +13 −19 lib/Carton/CLI.pm
View
@@ -14,6 +14,7 @@ use File::Basename ();
use File::Spec ();
use File::Temp ();
use Capture::Tiny 'capture';
+use Module::CPANfile;
use constant CARTON_LOCK_VERSION => '0.9';
our $DefaultMirror = 'http://cpan.metacpan.org/';
@@ -35,15 +36,15 @@ sub lock { $_[0]->{lock} }
sub local_mirror { File::Spec->rel2abs("$_[0]->{path}/cache") }
-sub download_from_build_file {
- my($self, $build_file, $local_mirror) = @_;
+sub download_from_cpanfile {
+ my($self, $cpanfile, $local_mirror) = @_;
my @modules = $self->list_dependencies;
$self->download_conservative(\@modules, $local_mirror, 1)
or die "Bundling modules failed\n";
}
-sub install_from_build_file {
+sub install_from_cpanfile {
my($self, $file) = @_;
my @modules;
@@ -60,12 +61,15 @@ sub install_from_build_file {
sub list_dependencies {
my $self = shift;
- my @deps = grep !/^perl~/, $self->run_cpanm_output("--showdeps", ".");
- for my $line (@deps) {
- chomp $line;
- }
+ my $cpanfile = Module::CPANfile->load;
+ my $prereq = $cpanfile->prereq;
- return @deps;
+ my $reqs = CPAN::Meta::Requirements->new;
+ $reqs->add_requirements($prereq->requirements_for($_, 'requires'))
+ for qw( configure build runtime);
+
+ my $hash = $reqs->as_string_hash;
+ return map "$_~$hash->{$_}", keys %$hash; # TODO refactor to not rely on string representation
}
sub install_modules {
View
@@ -138,9 +138,9 @@ sub cmd_bundle {
my $local_mirror = $self->carton->local_mirror;
- if (my $build_file = $self->has_build_file) {
- $self->print("Bundling modules using $build_file\n");
- $self->carton->download_from_build_file($build_file, $local_mirror);
+ if (my $cpanfile = $self->has_cpanfile) {
+ $self->print("Bundling modules using $cpanfile\n");
+ $self->carton->download_from_cpanfile($cpanfile, $local_mirror);
$self->carton->update_mirror_index($local_mirror);
} else {
$self->error("Can't locate build file\n");
@@ -168,18 +168,14 @@ sub cmd_install {
( $self->{use_local_mirror} && -d $local_mirror ? (mirror => $local_mirror) : () ),
);
- my $build_file = $self->has_build_file;
+ my $cpanfile = $self->has_cpanfile;
- if (@args) {
- $self->print("Installing modules from the command line\n");
- $self->carton->install_modules(\@args);
- $self->carton->update_lock_file($self->lock_file);
- } elsif ($self->{deployment} or not $build_file) {
+ if ($self->{deployment} or not $cpanfile) {
$self->print("Installing modules using carton.lock (deployment mode)\n");
$self->carton->install_from_lock;
- } elsif ($build_file) {
- $self->print("Installing modules using $build_file\n");
- $self->carton->install_from_build_file($build_file);
+ } elsif ($cpanfile) {
+ $self->print("Installing modules using $cpanfile\n");
+ $self->carton->install_from_cpanfile($cpanfile);
$self->carton->update_lock_file($self->lock_file);
} else {
$self->error("Can't locate build file or carton.lock\n");
@@ -208,7 +204,7 @@ sub cmd_uninstall {
}
my %root;
- if ($self->has_build_file) {
+ if ($self->has_cpanfile) {
for my $dep ($self->carton->list_dependencies) {
my($mod, $ver) = split /~/, $dep;
if (exists $index->{$mod}) {
@@ -251,13 +247,11 @@ sub mirror_file {
return $self->work_file("02packages.details.txt");
}
-sub has_build_file {
+sub has_cpanfile {
my $self = shift;
- my $file = (grep -e, qw( Build.PL Makefile.PL ))[0]
- or return;
-
- return $file;
+ return 'cpanfile' if -e 'cpanfile';
+ return;
}
sub cmd_show {
@@ -305,7 +299,7 @@ sub cmd_list {
sub cmd_check {
my($self, @args) = @_;
- my $file = $self->has_build_file
+ my $file = $self->has_cpanfile
or $self->error("Can't find a build file: nothing to check.\n");
$self->parse_options(\@args, "p|path=s", sub { $self->carton->{path} = $_[1] });

0 comments on commit 03ead7b

Please sign in to comment.