Skip to content

Commit

Permalink
remove Config framework, commands and alias
Browse files Browse the repository at this point in the history
  • Loading branch information
miyagawa committed Oct 13, 2011
1 parent f1fec33 commit 7a17594
Show file tree
Hide file tree
Showing 9 changed files with 19 additions and 233 deletions.
2 changes: 0 additions & 2 deletions Makefile.PL
Expand Up @@ -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;

Expand Down
22 changes: 8 additions & 14 deletions lib/Carton.pm
Expand Up @@ -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;
Expand All @@ -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);
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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}";
Expand All @@ -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}");
}
}

Expand Down
89 changes: 9 additions & 80 deletions lib/Carton/CLI.pm
Expand Up @@ -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;
Expand All @@ -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 {
Expand Down Expand Up @@ -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) {
Expand All @@ -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;

Expand Down Expand Up @@ -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;

Expand All @@ -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`");
Expand Down Expand Up @@ -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);
}
}
Expand Down Expand Up @@ -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;
Expand All @@ -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";
Expand All @@ -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);
}
}
Expand All @@ -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";
Expand Down
46 changes: 0 additions & 46 deletions lib/Carton/Config.pm

This file was deleted.

32 changes: 0 additions & 32 deletions lib/Carton/Doc/Config.pod

This file was deleted.

3 changes: 1 addition & 2 deletions xt/CLI.pm
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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) };
Expand Down
19 changes: 0 additions & 19 deletions xt/cli/alias.t

This file was deleted.

0 comments on commit 7a17594

Please sign in to comment.