summaryrefslogtreecommitdiff
path: root/Master/tlpkg/tlperl/lib/CPAN/Meta/Prereqs.pm
diff options
context:
space:
mode:
Diffstat (limited to 'Master/tlpkg/tlperl/lib/CPAN/Meta/Prereqs.pm')
-rw-r--r--Master/tlpkg/tlperl/lib/CPAN/Meta/Prereqs.pm160
1 files changed, 151 insertions, 9 deletions
diff --git a/Master/tlpkg/tlperl/lib/CPAN/Meta/Prereqs.pm b/Master/tlpkg/tlperl/lib/CPAN/Meta/Prereqs.pm
index c1c58f0a6a6..b6e6c73c9e1 100644
--- a/Master/tlpkg/tlperl/lib/CPAN/Meta/Prereqs.pm
+++ b/Master/tlpkg/tlperl/lib/CPAN/Meta/Prereqs.pm
@@ -2,13 +2,47 @@ use 5.006;
use strict;
use warnings;
package CPAN::Meta::Prereqs;
-our $VERSION = '2.120921'; # VERSION
+our $VERSION = '2.140640'; # VERSION
+# =head1 DESCRIPTION
+#
+# A CPAN::Meta::Prereqs object represents the prerequisites for a CPAN
+# distribution or one of its optional features. Each set of prereqs is
+# organized by phase and type, as described in L<CPAN::Meta::Prereqs>.
+#
+# =cut
use Carp qw(confess);
use Scalar::Util qw(blessed);
use CPAN::Meta::Requirements 2.121;
+# =method new
+#
+# my $prereq = CPAN::Meta::Prereqs->new( \%prereq_spec );
+#
+# This method returns a new set of Prereqs. The input should look like the
+# contents of the C<prereqs> field described in L<CPAN::Meta::Spec>, meaning
+# something more or less like this:
+#
+# my $prereq = CPAN::Meta::Prereqs->new({
+# runtime => {
+# requires => {
+# 'Some::Module' => '1.234',
+# ...,
+# },
+# ...,
+# },
+# ...,
+# });
+#
+# You can also construct an empty set of prereqs with:
+#
+# my $prereqs = CPAN::Meta::Prereqs->new;
+#
+# This empty set of prereqs is useful for accumulating new prereqs before finally
+# dumping the whole set into a structure or string.
+#
+# =cut
sub __legal_phases { qw(configure build test runtime develop) }
sub __legal_types { qw(requires recommends suggests conflicts) }
@@ -44,6 +78,19 @@ sub new {
return bless \%guts => $class;
}
+# =method requirements_for
+#
+# my $requirements = $prereqs->requirements_for( $phase, $type );
+#
+# This method returns a L<CPAN::Meta::Requirements> object for the given
+# phase/type combination. If no prerequisites are registered for that
+# combination, a new CPAN::Meta::Requirements object will be returned, and it may
+# be added to as needed.
+#
+# If C<$phase> or C<$type> are undefined or otherwise invalid, an exception will
+# be raised.
+#
+# =cut
sub requirements_for {
my ($self, $phase, $type) = @_;
@@ -66,6 +113,21 @@ sub requirements_for {
return $req;
}
+# =method with_merged_prereqs
+#
+# my $new_prereqs = $prereqs->with_merged_prereqs( $other_prereqs );
+#
+# my $new_prereqs = $prereqs->with_merged_prereqs( \@other_prereqs );
+#
+# This method returns a new CPAN::Meta::Prereqs objects in which all the
+# other prerequisites given are merged into the current set. This is primarily
+# provided for combining a distribution's core prereqs with the prereqs of one of
+# its optional features.
+#
+# The new prereqs object has no ties to the originals, and altering it further
+# will not alter them.
+#
+# =cut
sub with_merged_prereqs {
my ($self, $other) = @_;
@@ -96,6 +158,56 @@ sub with_merged_prereqs {
return (ref $self)->new(\%new_arg);
}
+# =method merged_requirements
+#
+# my $new_reqs = $prereqs->merged_requirements( \@phases, \@types );
+# my $new_reqs = $prereqs->merged_requirements( \@phases );
+# my $new_reqs = $preerqs->merged_requirements();
+#
+# This method joins together all requirements across a number of phases
+# and types into a new L<CPAN::Meta::Requirements> object. If arguments
+# are omitted, it defaults to "runtime", "build" and "test" for phases
+# and "requires" and "recommends" for types.
+#
+# =cut
+
+sub merged_requirements {
+ my ($self, $phases, $types) = @_;
+ $phases = [qw/runtime build test/] unless defined $phases;
+ $types = [qw/requires recommends/] unless defined $types;
+
+ confess "merged_requirements phases argument must be an arrayref"
+ unless ref $phases eq 'ARRAY';
+ confess "merged_requirements types argument must be an arrayref"
+ unless ref $types eq 'ARRAY';
+
+ my $req = CPAN::Meta::Requirements->new;
+
+ for my $phase ( @$phases ) {
+ unless ($phase =~ /\Ax_/i or grep { $phase eq $_ } $self->__legal_phases) {
+ confess "requested requirements for unknown phase: $phase";
+ }
+ for my $type ( @$types ) {
+ unless ($type =~ /\Ax_/i or grep { $type eq $_ } $self->__legal_types) {
+ confess "requested requirements for unknown type: $type";
+ }
+ $req->add_requirements( $self->requirements_for($phase, $type) );
+ }
+ }
+
+ $req->finalize if $self->is_finalized;
+
+ return $req;
+}
+
+
+# =method as_string_hash
+#
+# This method returns a hashref containing structures suitable for dumping into a
+# distmeta data structure. It is made up of hashes and strings, only; there will
+# be no Prereqs, CPAN::Meta::Requirements, or C<version> objects inside it.
+#
+# =cut
sub as_string_hash {
my ($self) = @_;
@@ -114,9 +226,22 @@ sub as_string_hash {
return \%hash;
}
+# =method is_finalized
+#
+# This method returns true if the set of prereqs has been marked "finalized," and
+# cannot be altered.
+#
+# =cut
sub is_finalized { $_[0]{finalized} }
+# =method finalize
+#
+# Calling C<finalize> on a Prereqs object will close it for further modification.
+# Attempting to make any changes that would actually alter the prereqs will
+# result in an exception being thrown.
+#
+# =cut
sub finalize {
my ($self) = @_;
@@ -128,6 +253,16 @@ sub finalize {
}
}
+# =method clone
+#
+# my $cloned_prereqs = $prereqs->clone;
+#
+# This method returns a Prereqs object that is identical to the original object,
+# but can be altered without affecting the original object. Finalization does
+# not survive cloning, meaning that you may clone a finalized set of prereqs and
+# then modify the clone.
+#
+# =cut
sub clone {
my ($self) = @_;
@@ -139,17 +274,19 @@ sub clone {
# ABSTRACT: a set of distribution prerequisites by phase and type
-
+__END__
=pod
+=encoding UTF-8
+
=head1 NAME
CPAN::Meta::Prereqs - a set of distribution prerequisites by phase and type
=head1 VERSION
-version 2.120921
+version 2.140640
=head1 DESCRIPTION
@@ -211,6 +348,17 @@ its optional features.
The new prereqs object has no ties to the originals, and altering it further
will not alter them.
+=head2 merged_requirements
+
+ my $new_reqs = $prereqs->merged_requirements( \@phases, \@types );
+ my $new_reqs = $prereqs->merged_requirements( \@phases );
+ my $new_reqs = $preerqs->merged_requirements();
+
+This method joins together all requirements across a number of phases
+and types into a new L<CPAN::Meta::Requirements> object. If arguments
+are omitted, it defaults to "runtime", "build" and "test" for phases
+and "requires" and "recommends" for types.
+
=head2 as_string_hash
This method returns a hashref containing structures suitable for dumping into a
@@ -268,9 +416,3 @@ This is free software; you can redistribute it and/or modify it under
the same terms as the Perl 5 programming language system itself.
=cut
-
-
-__END__
-
-
-