[carton] 148/472: Support cpanfile!

Lucas Kanashiro kanashiro-guest at moszumanska.debian.org
Fri Jul 24 00:38:42 UTC 2015


This is an automated email from the git hooks/post-receive script.

kanashiro-guest pushed a commit to branch master
in repository carton.

commit 03ead7bf8f5d16ce9c22e877ff8409ce5532c350
Author: Tatsuhiko Miyagawa <miyagawa at bulknews.net>
Date:   Thu Apr 12 19:35:18 2012 +0900

    Support cpanfile!
---
 lib/Carton.pm     | 20 ++++++++++++--------
 lib/Carton/CLI.pm | 32 +++++++++++++-------------------
 2 files changed, 25 insertions(+), 27 deletions(-)

diff --git a/lib/Carton.pm b/lib/Carton.pm
index 8a2ae25..f8cf443 100644
--- a/lib/Carton.pm
+++ b/lib/Carton.pm
@@ -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 {
diff --git a/lib/Carton/CLI.pm b/lib/Carton/CLI.pm
index 6bbf074..184fcf7 100644
--- a/lib/Carton/CLI.pm
+++ b/lib/Carton/CLI.pm
@@ -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] });

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-perl/packages/carton.git



More information about the Pkg-perl-cvs-commits mailing list