[carton] 437/472: Moo -> Class::Tiny

Lucas Kanashiro kanashiro-guest at moszumanska.debian.org
Fri Jul 24 00:39:34 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 082f6e75baabd21c1af9c5f06b8e91d52d643a0b
Author: Tatsuhiko Miyagawa <miyagawa at bulknews.net>
Date:   Sun Apr 19 18:56:31 2015 +0200

    Moo -> Class::Tiny
---
 cpanfile                       |  2 +-
 lib/Carton/Builder.pm          | 19 +++++++++----------
 lib/Carton/CLI.pm              | 15 +++++++--------
 lib/Carton/CPANfile.pm         | 27 ++++++++++++++++++++++-----
 lib/Carton/Dependency.pm       | 12 +++++++-----
 lib/Carton/Dist.pm             | 18 +++++++++++-------
 lib/Carton/Dist/Core.pm        |  7 +++----
 lib/Carton/Environment.pm      | 24 ++++++++++++------------
 lib/Carton/Index.pm            |  8 ++++----
 lib/Carton/Mirror.pm           |  6 ++----
 lib/Carton/Package.pm          |  8 ++------
 lib/Carton/Packer.pm           |  2 +-
 lib/Carton/Snapshot.pm         | 32 ++++++++++++++++++++++++--------
 lib/Carton/Snapshot/Emitter.pm |  2 +-
 lib/Carton/Snapshot/Parser.pm  |  2 +-
 lib/Carton/Tree.pm             |  6 ++----
 16 files changed, 109 insertions(+), 81 deletions(-)

diff --git a/cpanfile b/cpanfile
index 346c443..f6dcd3e 100644
--- a/cpanfile
+++ b/cpanfile
@@ -11,7 +11,7 @@ requires 'Module::CPANfile', 0.9031;
 requires 'Try::Tiny', 0.09;
 requires 'parent', 0.223;
 requires 'Getopt::Long', 2.39;
-requires 'Moo', 1.002;
+requires 'Class::Tiny', 1.001;
 requires 'Path::Tiny', 0.033;
 
 # MYMETA support
diff --git a/lib/Carton/Builder.pm b/lib/Carton/Builder.pm
index 9684b54..de456d7 100644
--- a/lib/Carton/Builder.pm
+++ b/lib/Carton/Builder.pm
@@ -1,14 +1,13 @@
 package Carton::Builder;
-use Moo;
-use warnings NONFATAL => 'all';
-no warnings 'once';
-
-has mirror  => (is => 'rw');
-has index   => (is => 'rw');
-has cascade => (is => 'rw', default => sub { 1 });
-has without => (is => 'rw', default => sub { [] });
-has cpanfile => (is => 'rw');
-has fatscript => (is => 'lazy');
+use strict;
+use Class::Tiny {
+    mirror => undef,
+    index  => undef,
+    cascade => sub { 1 },
+    without => sub { [] },
+    cpanfile => undef,
+    fatscript => sub { $_[0]->_build_fatscript },
+};
 
 sub effective_mirrors {
     my $self = shift;
diff --git a/lib/Carton/CLI.pm b/lib/Carton/CLI.pm
index e2e34ec..c1caf3d 100644
--- a/lib/Carton/CLI.pm
+++ b/lib/Carton/CLI.pm
@@ -1,7 +1,5 @@
 package Carton::CLI;
-use Moo;
-use warnings NONFATAL => 'all';
-
+use strict;
 use Config;
 use Getopt::Long;
 use Path::Tiny;
@@ -21,14 +19,15 @@ use constant { SUCCESS => 0, INFO => 1, WARN => 2, ERROR => 3 };
 
 our $UseSystem = 0; # 1 for unit testing
 
-has verbose => (is => 'rw');
-has carton  => (is => 'lazy');
-has mirror  => (is => 'rw', builder => 1,
-                coerce => sub { Carton::Mirror->new($_[0]) });
+use Class::Tiny {
+    verbose => undef,
+    carton => sub { $_[0]->_build_carton },
+    mirror => sub { $_[0]->_build_mirror },
+};
 
 sub _build_mirror {
     my $self = shift;
-    $ENV{PERL_CARTON_MIRROR} || $Carton::Mirror::DefaultMirror;
+    Carton::Mirror->new($ENV{PERL_CARTON_MIRROR} || $Carton::Mirror::DefaultMirror);
 }
 
 sub run {
diff --git a/lib/Carton/CPANfile.pm b/lib/Carton/CPANfile.pm
index 313866c..a60d690 100644
--- a/lib/Carton/CPANfile.pm
+++ b/lib/Carton/CPANfile.pm
@@ -1,14 +1,31 @@
 package Carton::CPANfile;
-use Moo;
-use warnings NONFATAL => 'all';
 use Path::Tiny ();
 use Module::CPANfile;
 
 use overload q{""} => sub { $_[0]->stringify }, fallback => 1;
 
-has path => (is => 'rw', coerce => sub { Path::Tiny->new($_[0]) }, handles => [ qw(stringify dirname) ]);
-has _cpanfile => (is => 'rw', handles => [ qw(prereqs) ]);
-has requirements => (is => 'rw', lazy => 1, builder => 1, handles => [ qw(required_modules requirements_for_module) ]);
+use subs 'path';
+
+use Class::Tiny {
+    path => undef,
+    _cpanfile => undef,
+    requirements => sub { $_[0]->_build_requirements },
+};
+
+sub stringify { shift->path->stringify(@_) }
+sub dirname   { shift->path->dirname(@_) }
+sub prereqs   { shift->_cpanfile->prereqs(@_) }
+sub required_modules { shift->requirements->required_modules(@_) }
+sub requirements_for_module { shift->requirements->requirements_for_module(@_) }
+
+sub path {
+    my $self = shift;
+    if (@_) {
+        $self->{path} = Path::Tiny->new($_[0]);
+    } else {
+        $self->{path};
+    }
+}
 
 sub load {
     my $self = shift;
diff --git a/lib/Carton/Dependency.pm b/lib/Carton/Dependency.pm
index 5b0584f..d3e11ac 100644
--- a/lib/Carton/Dependency.pm
+++ b/lib/Carton/Dependency.pm
@@ -1,10 +1,12 @@
 package Carton::Dependency;
-use Moo;
-use warnings NONFATAL => 'all';
+use strict;
+use Class::Tiny {
+    module => undef,
+    requirement => undef,
+    dist => undef,
+};
 
-has module => (is => 'rw');
-has requirement => (is => 'rw');
-has dist => (is => 'rw', handles => [ qw(requirements) ]);
+sub requirements { shift->dist->requirements(@_) }
 
 sub distname {
     my $self = shift;
diff --git a/lib/Carton/Dist.pm b/lib/Carton/Dist.pm
index 3ffede6..9310e70 100644
--- a/lib/Carton/Dist.pm
+++ b/lib/Carton/Dist.pm
@@ -1,13 +1,17 @@
 package Carton::Dist;
-use Moo;
-use warnings NONFATAL => 'all';
+use strict;
+use Class::Tiny {
+    name => undef,
+    pathname => undef,
+    provides => sub { +{} },
+    requirements => sub { $_[0]->_build_requirements },
+};
+
 use CPAN::Meta;
 
-has name     => (is => 'ro');
-has pathname => (is => 'rw');
-has provides => (is => 'rw', default => sub { +{} });
-has requirements => (is => 'rw', lazy => 1, builder => 1,
-                     handles => [ qw(add_string_requirement required_modules requirements_for_module) ]);
+sub add_string_requirement  { shift->requirements->add_string_requirement(@_) }
+sub required_modules        { shift->requirements->required_modules(@_) }
+sub requirements_for_module { shift->requirements->requirements_for_module(@_) }
 
 sub is_core { 0 }
 
diff --git a/lib/Carton/Dist/Core.pm b/lib/Carton/Dist/Core.pm
index f7a6a8a..760ce66 100644
--- a/lib/Carton/Dist/Core.pm
+++ b/lib/Carton/Dist/Core.pm
@@ -1,9 +1,8 @@
 package Carton::Dist::Core;
-use Moo;
-use warnings NONFATAL => 'all';
-extends 'Carton::Dist';
+use strict;
+use parent 'Carton::Dist';
 
-has module_version => (is => 'ro');
+use Class::Tiny qw( module_version );
 
 sub BUILDARGS {
     my($class, %args) = @_;
diff --git a/lib/Carton/Environment.pm b/lib/Carton/Environment.pm
index 3b75852..6a58944 100644
--- a/lib/Carton/Environment.pm
+++ b/lib/Carton/Environment.pm
@@ -1,30 +1,30 @@
 package Carton::Environment;
-use Moo;
-use warnings NONFATAL => 'all';
-
+use strict;
 use Carton::CPANfile;
 use Carton::Snapshot;
 use Carton::Error;
 use Carton::Tree;
 use Path::Tiny;
 
-has cpanfile => (is => 'rw');
-has snapshot => (is => 'lazy');
-has install_path => (is => 'rw', lazy => 1, builder => 1, coerce => sub { Path::Tiny->new($_[0])->absolute });
-has vendor_cache  => (is => 'lazy');
-has tree => (is => 'rw', lazy => 1, builder => 1);
+use Class::Tiny {
+    cpanfile => undef,
+    snapshot => sub { $_[0]->_build_snapshot },
+    install_path => sub { $_[0]->_build_install_path },
+    vendor_cache => sub { $_[0]->_build_vendor_cache },
+    tree => sub { $_[0]->_build_tree },
+};
 
 sub _build_snapshot {
     my $self = shift;
-    Carton::Snapshot->new(path => $self->cpanfile->stringify . ".snapshot");
+    Carton::Snapshot->new(path => $self->cpanfile . ".snapshot");
 }
 
 sub _build_install_path {
     my $self = shift;
     if ($ENV{PERL_CARTON_PATH}) {
-        return $ENV{PERL_CARTON_PATH};
+        return Path::Tiny->new($ENV{PERL_CARTON_PATH});
     } else {
-        return $self->cpanfile->dirname . "/local";
+        return $self->cpanfile->path->parent->child("local");
     }
 }
 
@@ -68,7 +68,7 @@ sub build {
         Carton::Error::CPANfileNotFound->throw(error => "Can't locate cpanfile: (@{[ $cpanfile_path || 'cpanfile' ]})");
     }
 
-    $self->install_path($install_path) if $install_path;
+    $self->install_path( Path::Tiny->new($install_path)->absolute ) if $install_path;
 
     $self;
 }
diff --git a/lib/Carton/Index.pm b/lib/Carton/Index.pm
index 675de1e..278095a 100644
--- a/lib/Carton/Index.pm
+++ b/lib/Carton/Index.pm
@@ -1,8 +1,8 @@
 package Carton::Index;
-use Moo;
-use warnings NONFATAL => 'all';
-
-has _packages => (is => 'rw', default => sub { +{} });
+use strict;
+use Class::Tiny {
+    _packages => sub { +{} },
+};
 
 sub add_package {
     my($self, $package) = @_;
diff --git a/lib/Carton/Mirror.pm b/lib/Carton/Mirror.pm
index 4320d9a..60bc937 100644
--- a/lib/Carton/Mirror.pm
+++ b/lib/Carton/Mirror.pm
@@ -1,11 +1,9 @@
 package Carton::Mirror;
-use Moo;
-use warnings NONFATAL => 'all';
+use strict;
+use Class::Tiny qw( url );
 
 our $DefaultMirror = 'http://cpan.metacpan.org/';
 
-has url => (is => 'ro');
-
 sub BUILDARGS {
     my($class, $url) = @_;
     return { url => $url };
diff --git a/lib/Carton/Package.pm b/lib/Carton/Package.pm
index 7d77c90..6b1f381 100644
--- a/lib/Carton/Package.pm
+++ b/lib/Carton/Package.pm
@@ -1,10 +1,6 @@
 package Carton::Package;
-use Moo;
-use warnings NONFATAL => 'all';
-
-has name     => (is => 'ro');
-has version  => (is => 'ro');
-has pathname => (is => 'ro');
+use strict;
+use Class::Tiny qw( name version pathname );
 
 sub BUILDARGS {
     my($class, @args) = @_;
diff --git a/lib/Carton/Packer.pm b/lib/Carton/Packer.pm
index 815c470..333aa09 100644
--- a/lib/Carton/Packer.pm
+++ b/lib/Carton/Packer.pm
@@ -1,5 +1,5 @@
 package Carton::Packer;
-use Moo;
+use Class::Tiny;
 use warnings NONFATAL => 'all';
 use App::FatPacker;
 use File::pushd ();
diff --git a/lib/Carton/Snapshot.pm b/lib/Carton/Snapshot.pm
index 40e5db6..9e57f18 100644
--- a/lib/Carton/Snapshot.pm
+++ b/lib/Carton/Snapshot.pm
@@ -1,6 +1,5 @@
 package Carton::Snapshot;
-use Moo;
-use warnings NONFATAL => 'all';
+use strict;
 use Config;
 use Carton::Dist;
 use Carton::Dist::Core;
@@ -19,10 +18,27 @@ use Module::CoreList;
 
 use constant CARTON_SNAPSHOT_VERSION => '1.0';
 
-has path    => (is => 'rw', coerce => sub { Path::Tiny->new($_[0]) });
-has version => (is => 'rw', default => sub { CARTON_SNAPSHOT_VERSION });
-has loaded  => (is => 'rw');
-has _distributions => (is => 'rw', default => sub { +[] });
+use subs 'path';
+use Class::Tiny {
+    path => undef,
+    version => sub { CARTON_SNAPSHOT_VERSION },
+    loaded => undef,
+    _distributions => sub { +[] },
+};
+
+sub BUILD {
+    my $self = shift;
+    $self->path( $self->{path} );
+}    
+
+sub path {
+    my $self = shift;
+    if (@_) {
+        $self->{path} = Path::Tiny->new($_[0]);
+    } else {
+        $self->{path};
+    }
+}
 
 sub load_if_exists {
     my $self = shift;
@@ -137,8 +153,8 @@ sub find_installs {
         return 0 unless $reqs->accepts_module($module->{name}, $module->{provides}{$module->{name}}{version});
 
         if (my $exist = $installs{$module->{name}}) {
-            my $old_ver = version->new($exist->{provides}{$module->{name}}{version});
-            my $new_ver = version->new($module->{provides}{$module->{name}}{version});
+            my $old_ver = version::->new($exist->{provides}{$module->{name}}{version});
+            my $new_ver = version::->new($module->{provides}{$module->{name}}{version});
             return $new_ver >= $old_ver;
         } else {
             return 1;
diff --git a/lib/Carton/Snapshot/Emitter.pm b/lib/Carton/Snapshot/Emitter.pm
index 059b883..9486ba7 100644
--- a/lib/Carton/Snapshot/Emitter.pm
+++ b/lib/Carton/Snapshot/Emitter.pm
@@ -1,5 +1,5 @@
 package Carton::Snapshot::Emitter;
-use Moo;
+use Class::Tiny;
 use warnings NONFATAL => 'all';
 
 sub emit {
diff --git a/lib/Carton/Snapshot/Parser.pm b/lib/Carton/Snapshot/Parser.pm
index badd31d..21aa0c1 100644
--- a/lib/Carton/Snapshot/Parser.pm
+++ b/lib/Carton/Snapshot/Parser.pm
@@ -1,5 +1,5 @@
 package Carton::Snapshot::Parser;
-use Moo;
+use Class::Tiny;
 use warnings NONFATAL => 'all';
 use Carton::Dist;
 use Carton::Error;
diff --git a/lib/Carton/Tree.pm b/lib/Carton/Tree.pm
index a73129d..6ce22a1 100644
--- a/lib/Carton/Tree.pm
+++ b/lib/Carton/Tree.pm
@@ -1,10 +1,8 @@
 package Carton::Tree;
-use Moo;
-use warnings NONFATAL => 'all';
+use strict;
 use Carton::Dependency;
 
-has cpanfile => (is => 'ro');
-has snapshot => (is => 'ro');
+use Class::Tiny qw( cpanfile snapshot );
 
 use constant STOP => -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