[carton] 115/472: remove Config framework, commands and alias

Lucas Kanashiro kanashiro-guest at moszumanska.debian.org
Fri Jul 24 00:38:39 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 7a175948b8e8e1ab4c5e2bc487d02e28358fec7c
Author: Tatsuhiko Miyagawa <miyagawa at bulknews.net>
Date:   Fri Oct 14 00:31:34 2011 +0900

    remove Config framework, commands and alias
---
 Makefile.PL               |  2 --
 lib/Carton.pm             | 22 +++++-------
 lib/Carton/CLI.pm         | 89 +++++------------------------------------------
 lib/Carton/Config.pm      | 46 ------------------------
 lib/Carton/Doc/Config.pod | 32 -----------------
 xt/CLI.pm                 |  3 +-
 xt/cli/alias.t            | 19 ----------
 xt/cli/config.t           | 36 -------------------
 xt/cli/mirror.t           |  3 +-
 9 files changed, 19 insertions(+), 233 deletions(-)

diff --git a/Makefile.PL b/Makefile.PL
index 2e63e89..e940f81 100644
--- a/Makefile.PL
+++ b/Makefile.PL
@@ -12,8 +12,6 @@ requires 'Term::ANSIColor', 1.12;
 requires 'Module::Metadata', 1.000003;
 requires 'Try::Tiny', 0.09;
 requires 'parent', 0.223;
-requires 'Config::GitLike', 1.05;
-requires 'Text::ParseWords', 3.10;
 requires 'local::lib', 1.008;
 requires 'Exception::Class', 1.32;
 
diff --git a/lib/Carton.pm b/lib/Carton.pm
index a338fe4..c90587f 100644
--- a/lib/Carton.pm
+++ b/lib/Carton.pm
@@ -7,7 +7,6 @@ use version; our $VERSION = qv('v0.9.0');
 
 use Cwd;
 use Config qw(%Config);
-use Carton::Config;
 use Carton::Util;
 use CPAN::Meta;
 use File::Path;
@@ -18,14 +17,11 @@ our $DefaultMirror = 'http://cpan.metacpan.org/';
 sub new {
     my($class, %args) = @_;
     bless {
-        config => $args{config},
+        path => $ENV{PERL_CARTON_PATH} || 'local',
+        mirror => $ENV{PERL_CARTON_MIRROR} || $DefaultMirror,
     }, $class;
 }
 
-sub config {
-    $_[0]->{config};
-}
-
 sub configure {
     my($self, %args) = @_;
     %{$self} = (%$self, %args);
@@ -98,7 +94,7 @@ sub install_conservative {
         $self->build_mirror_file($index, $self->{mirror_file});
     }
 
-    my $mirror = $self->config->get(key => 'cpanm.mirror') || $DefaultMirror;
+    my $mirror = $self->{mirror} || $DefaultMirror;
 
     $self->run_cpanm(
         "--mirror", $mirror,
@@ -272,16 +268,14 @@ sub run_cpanm_output {
         return <$kid>;
     } else {
         local $ENV{PERL_CPANM_OPT};
-        my $cpanm = $self->config->get(key => 'cpanm.path');
-        exec $cpanm, "--quiet", "-L", $self->config->get(key => 'environment.path'), @args;
+        exec "cpanm", "--quiet", "-L", $self->{path}, @args;
     }
 }
 
 sub run_cpanm {
     my($self, @args) = @_;
     local $ENV{PERL_CPANM_OPT};
-    my $cpanm = $self->config->get(key => 'cpanm.path');
-    !system $cpanm, "--quiet", "-L", $self->config->get(key => 'environment.path'), "--notest", @args;
+    !system "cpanm", "--quiet", "-L", $self->{path}, "--notest", @args;
 }
 
 sub update_lock_file {
@@ -309,7 +303,7 @@ sub find_installs {
 
     require File::Find;
 
-    my $libdir = $self->config->get(key => 'environment.path') . "/lib/perl5/$Config{archname}/.meta";
+    my $libdir = "$self->{path}/lib/perl5/$Config{archname}/.meta";
     return unless -e $libdir;
 
     my @installs;
@@ -381,7 +375,7 @@ sub uninstall {
     my $meta = $lock->{modules}{$module};
     (my $path_name = $meta->{name}) =~ s!::!/!g;
 
-    my $path = Cwd::realpath($self->config->get(key => 'environment.path'));
+    my $path = Cwd::realpath($self->{path});
     my $packlist = "$path/lib/perl5/$Config{archname}/auto/$path_name/.packlist";
 
     open my $fh, "<", $packlist or die "Couldn't locate .packlist for $meta->{name}";
@@ -394,7 +388,7 @@ sub uninstall {
 
     unlink $packlist;
     if ($meta->{dist}) { # safety guard not to rm -r auto/meta
-        File::Path::rmtree($self->config->get(key => 'environment.path') . "/lib/perl5/$Config{archname}/.meta/$meta->{dist}");
+        File::Path::rmtree("$self->{path}/lib/perl5/$Config{archname}/.meta/$meta->{dist}");
     }
 }
 
diff --git a/lib/Carton/CLI.pm b/lib/Carton/CLI.pm
index 2c48cb1..7683d6c 100644
--- a/lib/Carton/CLI.pm
+++ b/lib/Carton/CLI.pm
@@ -9,7 +9,6 @@ use Term::ANSIColor qw(colored);
 
 use Carton;
 use Carton::Util;
-use Carton::Config;
 use Carton::Error;
 use Carton::Tree;
 use Try::Tiny;
@@ -31,19 +30,9 @@ sub new {
     }, $class;
 }
 
-sub config {
-    my $self = shift;
-    $self->{config} ||= do {
-        my $config = Carton::Config->new(confname => "carton/config");
-        $config->load;
-        $config->load_defaults;
-        $config;
-    };
-}
-
 sub carton {
     my $self = shift;
-    $self->{carton} ||= Carton->new(config => $self->config);
+    $self->{carton} ||= Carton->new;
 }
 
 sub work_file {
@@ -72,12 +61,6 @@ sub run {
     push @commands, @ARGV;
 
     my $cmd = shift @commands || 'usage';
-
-    if (my @alias = $self->find_alias($cmd)) {
-        $cmd = shift @alias;
-        unshift @commands, @alias;
-    }
-
     my $call = $self->can("cmd_$cmd");
 
     if ($call) {
@@ -92,16 +75,6 @@ sub run {
     }
 }
 
-sub find_alias {
-    my($self, $cmd) = @_;
-
-    my $alias = $self->config->get(key => "alias.$cmd")
-        or return;
-
-    require Text::ParseWords;
-    return Text::ParseWords::shellwords($alias);
-}
-
 sub commands {
     my $self = shift;
 
@@ -161,7 +134,7 @@ sub cmd_version {
 sub cmd_install {
     my($self, @args) = @_;
 
-    $self->parse_options(\@args, "p|path=s", sub { $self->config->data->{'environment.path'} = $_[1] }, "deployment!" => \$self->{deployment});
+    $self->parse_options(\@args, "p|path=s", sub { $self->carton->{path} = $_[1] }, "deployment!" => \$self->{deployment});
 
     my $lock = $self->find_lock;
 
@@ -187,13 +160,13 @@ sub cmd_install {
         $self->error("Can't locate build file or carton.lock\n");
     }
 
-    $self->printf("Complete! Modules were installed into %s\n", $self->config->get(key => 'environment.path'), SUCCESS);
+    $self->printf("Complete! Modules were installed into %s\n", $self->carton->{path}, SUCCESS);
 }
 
 sub cmd_uninstall {
     my($self, @args) = @_;
 
-    $self->parse_options(\@args, "p|path=s", sub { $self->config->data->{'environment.path'} = $_[1] });
+    $self->parse_options(\@args, "p|path=s", sub { $self->carton->{path} = $_[1] });
 
     my $lock = $self->find_lock
         or $self->error("Can't find carton.lock: Run `carton install`");
@@ -244,51 +217,7 @@ sub cmd_uninstall {
 
     if (@missing) {
         $self->printf("Complete! Modules and its dependencies were uninstalled from %s\n",
-                      $self->config->get(key => 'environment.path'), SUCCESS);
-    }
-}
-
-sub cmd_config {
-    my($self, @args) = @_;
-
-    my($global, $local, $unset);
-    $self->parse_options(\@args, "global" => \$global, "local" => \$local, "unset" => \$unset);
-
-    # don't use $self->config
-    my $config = Carton::Config->new(confname => "carton/config");
-
-    my $filename;
-    if ($global) {
-        $filename = $config->user_file;
-        $config->load_file($filename) if -f $filename;
-    } elsif ($local) {
-        $filename = $config->dir_file;
-        $config->load_file($filename) if -f $filename;
-    } else {
-        $filename = $config->dir_file;
-        $config->load;
-    }
-
-    $config->load_defaults;
-
-    my($key, $value) = @args;
-
-    if (defined $key && $key !~ /\./) {
-        $self->error("key does not contain a section: $key\n");
-        return;
-    }
-
-    if (!@args) {
-        $self->print(my $dump = $config->dump);
-    } elsif ($unset) {
-        $config->set(key => $key, filename => $filename);
-    } elsif (defined $value) {
-        $config->set(key => $key, value => $value, filename => $filename);
-    } elsif (defined $key) {
-        my $val = $config->get(key => $key);
-        if (defined $val) {
-            $self->print($val . "\n")
-        }
+                      $self->carton->{path}, SUCCESS);
     }
 }
 
@@ -354,7 +283,7 @@ sub cmd_check {
     my $file = $self->has_build_file
         or $self->error("Can't find a build file: nothing to check.\n");
 
-    $self->parse_options(\@args, "p|path=s", sub { $self->config->data->{'environment.path'} = $_[1] });
+    $self->parse_options(\@args, "p|path=s", sub { $self->carton->{path} = $_[1] });
 
     my $lock = $self->carton->build_lock;
     my @deps = $self->carton->list_dependencies;
@@ -372,7 +301,7 @@ sub cmd_check {
 
     if ($res->{superflous}) {
         $self->printf("Following modules are found in %s but couldn't be tracked from your $file\n",
-                      $self->config->get(key => 'environment.path'), WARN);
+                      $self->carton->{path}, WARN);
         $self->carton->walk_down_tree($res->{superflous}, sub {
             my($module, $depth) = @_;
             my $line = "  " x $depth . "$module->{dist}\n";
@@ -383,7 +312,7 @@ sub cmd_check {
 
     if ($ok) {
         $self->printf("Dependencies specified in your $file are satisfied and matches with modules in %s.\n",
-                      $self->config->get(key => 'environment.path'), SUCCESS);
+                      $self->carton->{path}, SUCCESS);
     }
 }
 
@@ -403,7 +332,7 @@ sub cmd_exec {
     my @include;
     $self->parse_options(\@args, 'I=s@', \@include, "system", \$system);
 
-    my $path = $self->config->get(key => 'environment.path');
+    my $path = $self->carton->{path};
     my $lib  = join ",", @include, "$path/lib/perl5", ".";
 
     local $ENV{PERL5OPT} = "-Mlib::core::only -Mlib=$lib";
diff --git a/lib/Carton/Config.pm b/lib/Carton/Config.pm
deleted file mode 100644
index d10f991..0000000
--- a/lib/Carton/Config.pm
+++ /dev/null
@@ -1,46 +0,0 @@
-package Carton::Config;
-use strict;
-use warnings;
-
-use parent qw(Config::GitLike);
-
-use File::Basename ();
-use File::Path ();
-
-sub load_defaults {
-    my $self = shift;
-
-    return if $self->{loaded_defaults};
-
-    $self->data({}) unless $self->is_loaded;
-
-    my @defaults = (
-        [ 'environment', 'path' => 'local' ],
-        [ 'cpanm', 'path' => 'cpanm' ],
-        [ 'cpanm', 'mirror' => 'http://cpan.metacpan.org/' ],
-    );
-
-    for my $default (@defaults) {
-        my($section, $name, $value) = @$default;
-        my $v = $self->get(key => "$section.$name");
-        unless (defined $v) {
-            $self->define(section => $section, name => $name, value => $value, origin => 'module');
-        }
-    }
-
-    $self->{loaded_defaults} = 1;
-}
-
-sub set {
-    my($self, %args) = @_;
-
-    if ($args{filename}) {
-        my $dir = File::Basename::dirname($args{filename});
-        File::Path::mkpath([ $dir ], 0, 0777);
-    }
-
-    $self->SUPER::set(%args);
-}
-
-1;
-
diff --git a/lib/Carton/Doc/Config.pod b/lib/Carton/Doc/Config.pod
deleted file mode 100644
index 8edb808..0000000
--- a/lib/Carton/Doc/Config.pod
+++ /dev/null
@@ -1,32 +0,0 @@
-=head1 NAME
-
-Carton::Doc::Config - set and get configuration for carton
-
-=head1 SYNOPSIS
-
-  carton config
-  carton config key
-  carton config key value
-  carton config --unset key
-
-=head1 DESCRIPTION
-
-This command, much like C<git config> allows you to get and set config values for carton.
-
-=head1 OPTIONS
-
-=over 4
-
-=item --global
-
-Only loads and saves the config from your global config (C<$HOME/.carton/config>).
-
-=item --local
-
-Only loads and saves the config from your local config (C<.carton/config>).
-
-=item --unset
-
-Removes the key in the config.
-
-=back
diff --git a/xt/CLI.pm b/xt/CLI.pm
index aa8d06a..12bbbf3 100644
--- a/xt/CLI.pm
+++ b/xt/CLI.pm
@@ -10,7 +10,7 @@ sub cli {
     chdir $dir;
 
     my $app = Carton::CLI::Tested->new(dir => $dir);
-    $app->config->define(section => "cpanm", name => "mirror", value => "$ENV{HOME}/minicpan", origin => 'test');
+    $app->carton->{mirror} = "$ENV{HOME}/minicpan";
 
     return $app;
 }
@@ -47,7 +47,6 @@ sub print {
 
 sub run {
     my($self, @args) = @_;
-    delete $self->{config};
     $self->{output} = '';
     $self->{system_output} = capture_merged {
         eval { $self->SUPER::run(@args) };
diff --git a/xt/cli/alias.t b/xt/cli/alias.t
deleted file mode 100644
index 5dbb728..0000000
--- a/xt/cli/alias.t
+++ /dev/null
@@ -1,19 +0,0 @@
-use strict;
-use warnings;
-use Test::More;
-use xt::CLI;
-
-{
-    my $app;
-
-    $app = run("foo");
-    like $app->output, qr/Could not find command 'foo'/;
-
-    $app->run("config", "alias.foo", "version");
-
-    $app->run("foo");
-    like $app->output, qr/carton $Carton::VERSION/;
-}
-
-done_testing;
-
diff --git a/xt/cli/config.t b/xt/cli/config.t
deleted file mode 100644
index 7010550..0000000
--- a/xt/cli/config.t
+++ /dev/null
@@ -1,36 +0,0 @@
-use strict;
-use warnings;
-use Test::More;
-use xt::CLI;
-
-{
-    my $app = cli();
-
-    $app->run("config", "foo");
-    like $app->output, qr/key does not contain a section: foo/;
-
-    $app->run("config", "foo.bar");
-    is $app->output, '';
-
-    $app->run("config", "foo.bar", "baz");
-    $app->run("config", "foo.bar");
-    is $app->output, "baz\n";
-
-    $app->run("config", "--global", "foo.bar", "quux");
-    $app->run("config", "--global", "foo.bar");
-    is $app->output, "quux\n";
-
-    $app->run("config", "foo.bar");
-    is $app->output, "baz\n";
-
-    $app->run("config", "--unset", "foo.bar");
-    $app->run("config", "foo.bar");
-    is $app->output, "quux\n", "global config";
-
-    $app->run("config", "--unset", "--global", "foo.bar");
-    $app->run("config", "foo.bar");
-    is $app->output, "";
-}
-
-done_testing;
-
diff --git a/xt/cli/mirror.t b/xt/cli/mirror.t
index 1a75848..6d9197c 100644
--- a/xt/cli/mirror.t
+++ b/xt/cli/mirror.t
@@ -8,8 +8,7 @@ my $cwd = Cwd::cwd();
 {
     my $app = cli();
 
-    $app->run("config", "cpanm.mirror", "$cwd/xt/mirror");
-    $app->run("config", "cpanm.mirror");
+    $app->carton->{mirror} = "$cwd/xt/mirror";
     $app->run("install", "Hash::MultiValue");
 
     $app->run("list");

-- 
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