summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTatsuhiko Miyagawa <miyagawa@bulknews.net>2013-09-20 15:55:01 +0900
committerTatsuhiko Miyagawa <miyagawa@bulknews.net>2013-09-20 15:55:01 +0900
commit7b6cf13e1d1ebdaacdc932452ccc06089cc47e02 (patch)
treec068712b2d505fb04055a1f9ca47e9b88e981c80
parentbd6456c57b330070d1f13286dc4ffe6ff9998d26 (diff)
downloadcarton-7b6cf13e1d1ebdaacdc932452ccc06089cc47e02.tar.gz
Support git
-rw-r--r--cpanfile4
-rw-r--r--lib/Carton/CLI.pm16
-rw-r--r--lib/Carton/CPANfile.pm3
-rw-r--r--lib/Carton/Dist/Specific.pm27
-rw-r--r--lib/Carton/Snapshot.pm21
-rw-r--r--xt/cli/git.t26
6 files changed, 84 insertions, 13 deletions
diff --git a/cpanfile b/cpanfile
index e7285ac..2e3c196 100644
--- a/cpanfile
+++ b/cpanfile
@@ -6,7 +6,7 @@ requires 'perl', '5.8.5';
requires 'JSON', 2.53;
requires 'Module::Metadata', 1.000003;
-requires 'Module::CPANfile', 0.9031;
+requires 'Module::CPANfile', 1.0903;
requires 'Try::Tiny', 0.09;
requires 'parent', 0.223;
@@ -16,7 +16,7 @@ requires 'Moo', 1.002;
requires 'Path::Tiny', 0.022;
# MYMETA support
-requires 'App::cpanminus', 1.6940;
+requires 'App::cpanminus', 1.7102;
requires 'ExtUtils::MakeMaker', 6.64;
requires 'Module::Build', 0.4004;
diff --git a/lib/Carton/CLI.pm b/lib/Carton/CLI.pm
index 96b38e3..e31aed3 100644
--- a/lib/Carton/CLI.pm
+++ b/lib/Carton/CLI.pm
@@ -199,14 +199,15 @@ sub cmd_install {
$self->print("Installing modules using @{[$env->cpanfile]}\n");
}
- # TODO merge CPANfile git to mirror even if lock doesn't exist
- if ($env->snapshot->loaded) {
- my $index_file = $env->install_path->child("cache/modules/02packages.details.txt");
- $index_file->parent->mkpath;
+ # Gather git from cpanfile, even when .snapshot does not exist
+ $env->cpanfile->load;
+ $env->snapshot->preload_cpanfile($env->cpanfile);
- $env->snapshot->write_index($index_file);
- $builder->index($index_file);
- }
+ my $index_file = $env->install_path->child("cache/modules/02packages.details.txt");
+ $index_file->parent->mkpath;
+
+ $env->snapshot->write_index($index_file);
+ $builder->index($index_file);
if ($cached) {
$builder->mirror(Carton::Mirror->new($env->vendor_cache));
@@ -215,7 +216,6 @@ sub cmd_install {
$builder->install($env->install_path);
unless ($deployment) {
- $env->cpanfile->load;
$env->snapshot->find_installs($env->install_path, $env->cpanfile->requirements);
$env->snapshot->save;
}
diff --git a/lib/Carton/CPANfile.pm b/lib/Carton/CPANfile.pm
index 313866c..8c4f656 100644
--- a/lib/Carton/CPANfile.pm
+++ b/lib/Carton/CPANfile.pm
@@ -7,7 +7,7 @@ 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 _cpanfile => (is => 'rw', handles => [ qw(prereqs prereq_for_module merged_requirements) ]);
has requirements => (is => 'rw', lazy => 1, builder => 1, handles => [ qw(required_modules requirements_for_module) ]);
sub load {
@@ -15,6 +15,7 @@ sub load {
$self->_cpanfile( Module::CPANfile->load($self->path) );
}
+# TODO features?
sub _build_requirements {
my $self = shift;
my $reqs = CPAN::Meta::Requirements->new;
diff --git a/lib/Carton/Dist/Specific.pm b/lib/Carton/Dist/Specific.pm
new file mode 100644
index 0000000..c4922d6
--- /dev/null
+++ b/lib/Carton/Dist/Specific.pm
@@ -0,0 +1,27 @@
+package Carton::Dist::Specific;
+use Moo;
+use warnings NONFATAL => 'all';
+
+use URI;
+use File::Basename ();
+
+has 'module' => (is => 'rw');
+has 'requirement' => (is => 'rw');
+
+sub provides {
+ my $self = shift;
+ return {
+ $self->module => {
+ version => $self->requirement->version, # FIXME version can be a Range
+ },
+ };
+}
+
+sub pathname {
+ my $self = shift;
+ my $uri = $self->requirement->git;
+ $uri .= '@' . $self->requirement->ref if $self->requirement->ref;
+ $uri;
+}
+
+1;
diff --git a/lib/Carton/Snapshot.pm b/lib/Carton/Snapshot.pm
index 40e5db6..88dbd06 100644
--- a/lib/Carton/Snapshot.pm
+++ b/lib/Carton/Snapshot.pm
@@ -4,6 +4,7 @@ use warnings NONFATAL => 'all';
use Config;
use Carton::Dist;
use Carton::Dist::Core;
+use Carton::Dist::Specific;
use Carton::Error;
use Carton::Package;
use Carton::Index;
@@ -99,7 +100,8 @@ sub packages {
my @packages;
for my $dist ($self->distributions) {
- while (my($package, $provides) = each %{$dist->provides}) {
+ my $provides = $dist->provides;
+ while (my($package, $provides) = each %$provides) {
# TODO what if duplicates?
push @packages, Carton::Package->new($package, $provides->{version}, $dist->pathname);
}
@@ -154,9 +156,11 @@ sub find_installs {
for qw( configure build runtime );
if ($accepts->($module)) {
+ my $pathname = $module->{source} && $module->{source} eq 'git'
+ ? join('@', $module->{uri}, $module->{revision}) : $module->{pathname};
$installs{$module->{name}} = Carton::Dist->new(
name => $module->{dist},
- pathname => $module->{pathname},
+ pathname => $pathname,
provides => $module->{provides},
version => $module->{version},
requirements => $reqs,
@@ -172,4 +176,17 @@ sub find_installs {
$self->_distributions(\@new_dists);
}
+sub preload_cpanfile {
+ my($self, $cpanfile) = @_;
+
+ my $reqs = $cpanfile->merged_requirements;
+ for my $module ($reqs->required_modules) {
+ my $prereq = $cpanfile->prereq_for_module($module) or next;
+ if ($prereq->requirement->git) {
+ my $dist = Carton::Dist::Specific->new(module => $module, requirement => $prereq->requirement);
+ $self->add_distribution($dist);
+ }
+ }
+}
+
1;
diff --git a/xt/cli/git.t b/xt/cli/git.t
new file mode 100644
index 0000000..71f972d
--- /dev/null
+++ b/xt/cli/git.t
@@ -0,0 +1,26 @@
+use strict;
+use Test::More;
+use xt::CLI;
+
+plan skip_all => 'Travis' if $ENV{TRAVIS};
+
+subtest 'carton install with git', sub {
+ my $app = cli();
+
+ $app->write_cpanfile(<<EOF);
+requires 'Hash::MultiValue', '0.15',
+ git => 'https://github.com/miyagawa/Hash-MultiValue.git', ref => '0.15';
+EOF
+
+ $app->run("install");
+ $app->run("list");
+ like $app->stdout, qr/Hash-MultiValue-759bf1b/;
+
+ $app->clean_local;
+ $app->run("install", "--deployment");
+ $app->run("list");
+ like $app->stdout, qr/Hash-MultiValue-759bf1b/;
+};
+
+done_testing;
+