Permalink
Browse files

Added experimental prereq_for_module and options_for_module

  • Loading branch information...
1 parent fa1556f commit 6fd84c39bfb2fbeafbb1a01bcbb81921a8d5bf9d @miyagawa committed Sep 19, 2013
Showing with 36 additions and 32 deletions.
  1. +8 −2 lib/Module/CPANfile.pm
  2. +10 −0 lib/Module/CPANfile/Prereqs.pm
  3. +9 −0 lib/Module/CPANfile/Requirement.pm
  4. +9 −30 t/requirement.t
View
@@ -88,9 +88,15 @@ sub prereq_specs {
$self->prereqs->as_string_hash;
}
-sub options_for_module {
- my $self = shift;
+sub prereq_for_module {
+ my($self, $module) = @_;
+ $self->{_prereqs}->find($module);
+}
+sub options_for_module {
+ my($self, $module) = @_;
+ my $prereq = $self->prereq_for_module($module) or return;
+ $prereq->requirement->options;
}
sub merge_meta {
@@ -74,6 +74,16 @@ sub prereq_each {
}
}
+sub find {
+ my($self, $module) = @_;
+
+ for my $prereq (@{$self->{prereqs}}) {
+ return $prereq if $prereq->module eq $module;
+ }
+
+ return;
+}
+
sub identifiers {
my $self = shift;
keys %{$self->{features}};
@@ -7,6 +7,15 @@ sub as_hashref {
return +{ %$self };
}
+sub options {
+ my $self = shift;
+
+ my $hash = $self->as_hashref;
+ delete $hash->{$_} for qw( name version );
+
+ $hash;
+}
+
sub new {
my ($class, %args) = @_;
View
@@ -10,21 +10,18 @@ requires 'Plack', '0.9970',
FILE
my $file = Module::CPANfile->load;
-
- # backword compatibility
is_deeply $file->prereq_specs, {
runtime => {
requires => { 'Plack' => '0.9970' },
},
};
- my $got = $file->prereq_specs->{runtime}->{requires}->{Plack};
- isa_ok $got, 'Module::CPANfile::Requirement';
- is_deeply $got->as_hashref, {
- name => 'Plack',
- version => '0.9970',
- git => 'git://github.com/plack/Plack.git',
- rev => '0.9970',
+ my $req = $file->prereqs->requirements_for(runtime => 'requires');
+ is $req->requirements_for_module('Plack'), '0.9970';
+
+ is_deeply $file->options_for_module('Plack'), {
+ git => 'git://github.com/plack/Plack.git',
+ rev => '0.9970',
};
};
@@ -35,19 +32,13 @@ requires 'Plack', # drop version
FILE
my $file = Module::CPANfile->load;
-
- # backword compatibility
is_deeply $file->prereq_specs, {
runtime => {
requires => { 'Plack' => 0 },
},
};
- my $got = $file->prereq_specs->{runtime}->{requires}->{Plack};
- isa_ok $got, 'Module::CPANfile::Requirement';
- is_deeply $got->as_hashref, {
- name => 'Plack',
- version => '0',
+ is_deeply $file->options_for_module('Plack'), {
git => 'git://github.com/plack/Plack.git',
rev => '0.9970',
};
@@ -59,19 +50,13 @@ requires 'Plack', '0.9970', git => 'git://github.com/plack/Plack.git';
FILE
my $file = Module::CPANfile->load;
-
- # backword compatibility
is_deeply $file->prereq_specs, {
runtime => {
requires => { 'Plack' => '0.9970' },
},
};
- my $got = $file->prereq_specs->{runtime}->{requires}->{Plack};
- isa_ok $got, 'Module::CPANfile::Requirement';
- is_deeply $got->as_hashref, {
- name => 'Plack',
- version => '0.9970',
+ is_deeply $file->options_for_module('Plack'), {
git => 'git://github.com/plack/Plack.git',
};
};
@@ -82,19 +67,13 @@ requires 'Plack', git => 'git://github.com/plack/Plack.git';
FILE
my $file = Module::CPANfile->load;
-
- # backword compatibility
is_deeply $file->prereq_specs, {
runtime => {
requires => { 'Plack' => 0 },
},
};
- my $got = $file->prereq_specs->{runtime}->{requires}->{Plack};
- isa_ok $got, 'Module::CPANfile::Requirement';
- is_deeply $got->as_hashref, {
- name => 'Plack',
- version => 0,
+ is_deeply $file->options_for_module('Plack'), {
git => 'git://github.com/plack/Plack.git',
};
};

0 comments on commit 6fd84c3

Please sign in to comment.