Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable the use of cpanfile mirror syntax #269

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions lib/Carton/CLI.pm
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,11 @@ sub cmd_install {

if ($cached) {
$builder->mirror(Carton::Mirror->new($env->vendor_cache));
} else {
$env->cpanfile->load;
if (my $cpanfile_mirror = $env->cpanfile->mirror) {
$builder->mirror(Carton::Mirror->new($cpanfile_mirror));
}
}

$builder->install($env->install_path);
Expand Down Expand Up @@ -352,6 +357,8 @@ sub cmd_update {
mirror => $self->mirror,
cpanfile => $env->cpanfile,
);
$builder->mirror(Carton::Mirror->new($env->cpanfile->mirror))
if $env->cpanfile->mirror;
$builder->update($env->install_path, @modules);

$env->snapshot->find_installs($env->install_path, $env->cpanfile->requirements);
Expand Down
1 change: 1 addition & 0 deletions lib/Carton/CPANfile.pm
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ use Class::Tiny {

sub stringify { shift->path->stringify(@_) }
sub dirname { shift->path->dirname(@_) }
sub mirror { @{shift->_cpanfile->mirrors}[0] }
sub prereqs { shift->_cpanfile->prereqs(@_) }
sub required_modules { shift->requirements->required_modules(@_) }
sub requirements_for_module { shift->requirements->requirements_for_module(@_) }
Expand Down
50 changes: 50 additions & 0 deletions xt/cli/cpanfile.t
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,15 @@ use Test::More;
use lib ".";
use xt::CLI;

subtest 'builder mirrors' => sub {
require Carton::Builder;
my $builder = Carton::Builder->new(mirror => Carton::Mirror->new('/tmp'));
my $mirrors = [ $builder->effective_mirrors ];
is @$mirrors, 3, 'three mirrors';
is_deeply $mirrors->[0], {url => '/tmp'}, 'custom mirror';
};


subtest 'carton install --cpanfile' => sub {
my $app = cli();
$app->write_file('cpanfile.foo', <<EOF);
Expand Down Expand Up @@ -41,5 +50,46 @@ EOF
ok $app->dir->child('cpanfile.foo.snapshot')->exists;
};

subtest 'mirrors' => sub {
my $app = cli();
my $cwd = Path::Tiny->cwd;

local $ENV{PERL_CARTON_CPANFILE} = $app->dir->child('cpanfile.mirror')->absolute;

$app->write_file('cpanfile.mirror', <<EOF);
mirror '$cwd/xt/mirror';
requires 'Hash::MultiValue';
EOF

$app->run("install");
# diag $app->stdout;
# diag $app->stderr;

$app->run("list");
like $app->stdout, qr/^Hash-MultiValue-0\.08/m;

ok $app->dir->child('cpanfile.mirror.snapshot')->exists;
};

subtest 'mirror / dist syntax for requires' => sub {
my $app = cli();
my $cwd = Path::Tiny->cwd;

local $ENV{PERL_CARTON_CPANFILE} = $app->dir->child('cpanfile.mirror')->absolute;

$app->write_file('cpanfile.mirror', <<EOF);
requires 'Hash::MultiValue',
dist => 'MIYAGAWA/Hash-MultiValue-0.08.tar.gz',
mirror => 'file://$cwd/xt/mirror';
EOF

$app->run("install");
$app->run("list");
like $app->stdout, qr/^Hash-MultiValue-0\.08/m;

ok $app->dir->child('cpanfile.mirror.snapshot')->exists;
};


done_testing;

36 changes: 36 additions & 0 deletions xt/cli/update.t
Original file line number Diff line number Diff line change
Expand Up @@ -75,5 +75,41 @@ EOF
}
};

subtest 'carton update from mirror' => sub {
my $app = cli();
my $cwd = Path::Tiny->cwd;

local $ENV{PERL_CARTON_CPANFILE} = $app->dir->child('cpanfile.mirror')->absolute;

$app->write_file('cpanfile.mirror', <<EOF);
mirror '$cwd/xt/mirror';
requires 'Hash::MultiValue';
EOF

$app->run("install");
$app->run("update");
# diag $app->stdout;
# diag $app->stderr;

like $app->stdout, qr/^Hash::MultiValue is up to date\. \(0\.08\)/m;

ok $app->dir->child('cpanfile.mirror.snapshot')->exists;

# Again, without mirror - will update to latest version
$app->write_file('cpanfile.mirror', <<EOF);
requires 'Hash::MultiValue';
EOF

$app->run("update");
# installed...
like $app->stdout,
qr/Successfully installed Hash-MultiValue-[\.0-9]+ \(upgraded from 0\.08\)$/m;

$app->run("list");
like $app->stdout, qr/Hash-MultiValue-[\.0-9]+/, 'present';
unlike $app->stdout, qr/Hash-MultiValue-0\.08/, 'not old';
};


done_testing;