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

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

commit c47061888c5075376c78208c2d816588aa0f6687
Author: Tatsuhiko Miyagawa <miyag...@bulknews.net>
Date:   Sat Jun 1 18:19:11 2013 +0900

    Refactor install/bundle to a new Builder class.
---
 lib/Carton.pm         | 51 +++++++++++++-------------------------------
 lib/Carton/Builder.pm | 59 +++++++++++++++++++++++++++++++++++++++++++++++++++
 lib/Carton/Mirror.pm  | 25 ++++++++++++++++++++++
 3 files changed, 99 insertions(+), 36 deletions(-)

diff --git a/lib/Carton.pm b/lib/Carton.pm
index 0ae437d..7fffe82 100644
--- a/lib/Carton.pm
+++ b/lib/Carton.pm
@@ -6,6 +6,8 @@ use 5.008_005;
 use version; our $VERSION = version->declare("v0.9.52");
 
 use Config qw(%Config);
+use Carton::Builder;
+use Carton::Mirror;
 use Carton::Util;
 use CPAN::Meta;
 use File::Path ();
@@ -14,13 +16,12 @@ use File::Temp ();
 use Module::CPANfile;
 
 use constant CARTON_LOCK_VERSION => '0.9';
-our $DefaultMirror = 'http://cpan.metacpan.org/';
 
 sub new {
     my($class, %args) = @_;
     bless {
         path => $ENV{PERL_CARTON_PATH} || 'local',
-        mirror => $ENV{PERL_CARTON_MIRROR} || $DefaultMirror,
+        mirror => $ENV{PERL_CARTON_MIRROR} || $Carton::Mirror::DefaultMirror,
     }, $class;
 }
 
@@ -28,21 +29,9 @@ sub local_cache {
     File::Spec->rel2abs("vendor/cache");
 }
 
-sub effective_mirrors {
-    my($self, $cached) = @_;
-
-    # push default CPAN mirror always, as a fallback
-    my @mirrors;
-    push @mirrors, ($cached ? $self->local_cache : $self->{mirror});
-    push @mirrors, $DefaultMirror if $self->use_darkpan;
-    push @mirrors, 'http://backpan.perl.org/';
-
-    @mirrors;
-}
-
 sub use_darkpan {
     my $self = shift;
-    $self->{mirror} ne $DefaultMirror;
+    $self->{mirror} ne $Carton::Mirror::DefaultMirror;
 }
 
 sub bundle {
@@ -50,15 +39,12 @@ sub bundle {
 
     $lock->write_index($self->{mirror_file});
 
-    local $self->{path} = File::Temp::tempdir(CLEANUP => 1); # ignore installed
-
-    $self->run_cpanm(
-        (map { ("--mirror", $_) } $self->effective_mirrors),
-        "--mirror-index", $self->{mirror_file},
-        "--skip-satisfied",
-        "--save-dists", $self->local_cache,
-        "--installdeps", ".",
+    my $builder = Carton::Builder->new(
+        mirror => Carton::Mirror->new($self->{mirror}),
+        index  => $self->{mirror_file},
     );
+
+    $builder->bundle($self->local_cache);
 }
 
 sub install {
@@ -69,20 +55,13 @@ sub install {
         $lock->write_index($self->{mirror_file});
     }
 
-    $self->run_cpanm(
-        (map { ("--mirror", $_) } $self->effective_mirrors($cached)),
-        "--skip-satisfied",
-        ( $lock ? ("--mirror-index", $self->{mirror_file}) : () ),
-        ( $cascade ? "--cascade-search" : () ),
-        ( $self->use_darkpan ? "--mirror-only" : () ),
-        "--installdeps", ".",
-    ) or die "Installing modules failed\n";
-}
+    my $mirror  = Carton::Mirror->new($cached ? $self->local_cache : 
$self->{mirror});
+    my $builder = Carton::Builder->new(
+        mirror => $mirror,
+        index  => $lock ? $self->{mirror_file} : undef,
+    );
 
-sub run_cpanm {
-    my($self, @args) = @_;
-    local $ENV{PERL_CPANM_OPT};
-    !system "cpanm", "--quiet", "-L", $self->{path}, "--notest", @args;
+    $builder->install($self->{path}, $cascade);
 }
 
 sub update_lock_file {
diff --git a/lib/Carton/Builder.pm b/lib/Carton/Builder.pm
new file mode 100644
index 0000000..3b0a5e7
--- /dev/null
+++ b/lib/Carton/Builder.pm
@@ -0,0 +1,59 @@
+package Carton::Builder;
+use strict;
+use Moo;
+
+has mirror  => (is => 'ro');
+has index   => (is => 'ro');
+
+sub effective_mirrors {
+    my $self = shift;
+
+    # push default CPAN mirror always, as a fallback
+    my @mirrors = ($self->mirror);
+    push @mirrors, Carton::Mirror->default if $self->use_darkpan;
+    push @mirrors, Carton::Mirror->new('http://backpan.perl.org/');
+
+    @mirrors;
+}
+
+sub use_darkpan {
+    my $self = shift;
+    ! $self->mirror->is_default;
+}
+
+sub bundle {
+    my($self, $path) = @_;
+
+    my $temp = File::Temp::tempdir(CLEANUP => 1); # ignore installed
+
+    $self->run_cpanm(
+        "-L", $temp,
+        (map { ("--mirror", $_->url) } $self->effective_mirrors),
+        "--mirror-index", $self->index,
+        "--skip-satisfied",
+        "--save-dists", $path,
+        "--installdeps", ".",
+    );
+}
+
+sub install {
+    my($self, $path, $cascade) = @_;
+
+    $self->run_cpanm(
+        "-L", $path,
+        (map { ("--mirror", $_->url) } $self->effective_mirrors),
+        "--skip-satisfied",
+        ( $self->index ? ("--mirror-index", $self->index) : () ),
+        ( $cascade ? "--cascade-search" : () ),
+        ( $self->use_darkpan ? "--mirror-only" : () ),
+        "--installdeps", ".",
+    ) or die "Installing modules failed\n";
+}
+
+sub run_cpanm {
+    my($self, @args) = @_;
+    local $ENV{PERL_CPANM_OPT};
+    !system "cpanm", "--quiet", "--notest", @args;
+}
+
+1;
diff --git a/lib/Carton/Mirror.pm b/lib/Carton/Mirror.pm
new file mode 100644
index 0000000..b5ccfa8
--- /dev/null
+++ b/lib/Carton/Mirror.pm
@@ -0,0 +1,25 @@
+package Carton::Mirror;
+use strict;
+use Moo;
+
+our $DefaultMirror = 'http://cpan.metacpan.org/';
+
+has url => (is => 'ro');
+
+sub BUILDARGS {
+    my($class, $url) = @_;
+    return { url => $url };
+}
+
+sub default {
+    my $class = shift;
+    $class->new($DefaultMirror);
+}
+
+sub is_default {
+    my $self = shift;
+    $self->url eq $DefaultMirror;
+}
+
+1;
+

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

_______________________________________________
Pkg-perl-cvs-commits mailing list
Pkg-perl-cvs-commits@lists.alioth.debian.org
http://lists.alioth.debian.org/cgi-bin/mailman/listinfo/pkg-perl-cvs-commits

Reply via email to