X-Git-Url: https://perl5.git.perl.org/perl5.git/blobdiff_plain/4690a2e02d47daf03446be6bc0143d8aa16bdb9f..f33f0562d25702270132a7cd9a85866f61c34473:/cpan/CPAN-Meta/lib/CPAN/Meta/Prereqs.pm diff --git a/cpan/CPAN-Meta/lib/CPAN/Meta/Prereqs.pm b/cpan/CPAN-Meta/lib/CPAN/Meta/Prereqs.pm index 8a13eb1..d4e93fd 100644 --- a/cpan/CPAN-Meta/lib/CPAN/Meta/Prereqs.pm +++ b/cpan/CPAN-Meta/lib/CPAN/Meta/Prereqs.pm @@ -3,7 +3,7 @@ use strict; use warnings; package CPAN::Meta::Prereqs; -our $VERSION = '2.150005'; +our $VERSION = '2.150010'; #pod =head1 DESCRIPTION #pod @@ -45,6 +45,7 @@ use CPAN::Meta::Requirements 2.121; #pod #pod =cut +# note we also accept anything matching /\Ax_/i sub __legal_phases { qw(configure build test runtime develop) } sub __legal_types { qw(requires recommends suggests conflicts) } @@ -114,6 +115,40 @@ sub requirements_for { return $req; } +#pod =method phases +#pod +#pod my @phases = $prereqs->phases; +#pod +#pod This method returns the list of all phases currently populated in the prereqs +#pod object, suitable for iterating. +#pod +#pod =cut + +sub phases { + my ($self) = @_; + + my %is_legal_phase = map {; $_ => 1 } $self->__legal_phases; + grep { /\Ax_/i or $is_legal_phase{$_} } keys %{ $self->{prereqs} }; +} + +#pod =method types_in +#pod +#pod my @runtime_types = $prereqs->types_in('runtime'); +#pod +#pod This method returns the list of all types currently populated in the prereqs +#pod object for the provided phase, suitable for iterating. +#pod +#pod =cut + +sub types_in { + my ($self, $phase) = @_; + + return unless $phase =~ /\Ax_/i or grep { $phase eq $_ } $self->__legal_phases; + + my %is_legal_type = map {; $_ => 1 } $self->__legal_types; + grep { /\Ax_/i or $is_legal_type{$_} } keys %{ $self->{prereqs}{$phase} }; +} + #pod =method with_merged_prereqs #pod #pod my $new_prereqs = $prereqs->with_merged_prereqs( $other_prereqs ); @@ -139,8 +174,9 @@ sub with_merged_prereqs { my %new_arg; - for my $phase ($self->__legal_phases) { - for my $type ($self->__legal_types) { + for my $phase (__uniq(map { $_->phases } @prereq_objs)) { + for my $type (__uniq(map { $_->types_in($phase) } @prereq_objs)) { + my $req = CPAN::Meta::Requirements->new; for my $prereq (@prereq_objs) { @@ -215,8 +251,8 @@ sub as_string_hash { my %hash; - for my $phase ($self->__legal_phases) { - for my $type ($self->__legal_types) { + for my $phase ($self->phases) { + for my $type ($self->types_in($phase)) { my $req = $self->requirements_for($phase, $type); next unless $req->required_modules; @@ -271,6 +307,11 @@ sub clone { my $clone = (ref $self)->new( $self->as_string_hash ); } +sub __uniq { + my (%s, $u); + grep { defined($_) ? !$s{$_}++ : !$u++ } @_; +} + 1; # ABSTRACT: a set of distribution prerequisites by phase and type @@ -285,7 +326,7 @@ CPAN::Meta::Prereqs - a set of distribution prerequisites by phase and type =head1 VERSION -version 2.150005 +version 2.150010 =head1 DESCRIPTION @@ -333,6 +374,20 @@ be added to as needed. If C<$phase> or C<$type> are undefined or otherwise invalid, an exception will be raised. +=head2 phases + + my @phases = $prereqs->phases; + +This method returns the list of all phases currently populated in the prereqs +object, suitable for iterating. + +=head2 types_in + + my @runtime_types = $prereqs->types_in('runtime'); + +This method returns the list of all types currently populated in the prereqs +object for the provided phase, suitable for iterating. + =head2 with_merged_prereqs my $new_prereqs = $prereqs->with_merged_prereqs( $other_prereqs ); @@ -405,11 +460,15 @@ David Golden Ricardo Signes +=item * + +Adam Kennedy + =back =head1 COPYRIGHT AND LICENSE -This software is copyright (c) 2010 by David Golden and Ricardo Signes. +This software is copyright (c) 2010 by David Golden, Ricardo Signes, Adam Kennedy and Contributors. This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.