use warnings;
package CPAN::Meta::Prereqs;
-our $VERSION = '2.150005';
+our $VERSION = '2.150010';
#pod =head1 DESCRIPTION
#pod
#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) }
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 );
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) {
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;
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
=head1 VERSION
-version 2.150005
+version 2.150010
=head1 DESCRIPTION
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 );
Ricardo Signes <rjbs@cpan.org>
+=item *
+
+Adam Kennedy <adamk@cpan.org>
+
=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.