/usr/share/perl5/Module/CPANfile/Prereqs.pm is in libmodule-cpanfile-perl 1.1002-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 | package Module::CPANfile::Prereqs;
use strict;
use Carp ();
use CPAN::Meta::Feature;
use Module::CPANfile::Prereq;
sub from_cpan_meta {
my($class, $prereqs) = @_;
my $self = $class->new;
for my $phase (keys %$prereqs) {
for my $type (keys %{ $prereqs->{$phase} }) {
while (my($module, $requirement) = each %{ $prereqs->{$phase}{$type} }) {
$self->add_prereq(
phase => $phase,
type => $type,
module => $module,
requirement => Module::CPANfile::Requirement->new(name => $module, version => $requirement),
);
}
}
}
$self;
}
sub new {
my $class = shift;
bless {
prereqs => [],
features => {},
}, $class;
}
sub add_feature {
my($self, $identifier, $description) = @_;
$self->{features}{$identifier} = { description => $description };
}
sub add_prereq {
my($self, %args) = @_;
$self->add( Module::CPANfile::Prereq->new(%args) );
}
sub add {
my($self, $prereq) = @_;
push @{$self->{prereqs}}, $prereq;
}
sub as_cpan_meta {
my $self = shift;
$self->{cpanmeta} ||= $self->build_cpan_meta;
}
sub build_cpan_meta {
my($self, $identifier) = @_;
my $prereq_spec = {};
$self->prereq_each($identifier, sub {
my $prereq = shift;
$prereq_spec->{$prereq->phase}{$prereq->type}{$prereq->module} = $prereq->requirement->version;
});
CPAN::Meta::Prereqs->new($prereq_spec);
}
sub prereq_each {
my($self, $identifier, $code) = @_;
for my $prereq (@{$self->{prereqs}}) {
next unless $prereq->match_feature($identifier);
$code->($prereq);
}
}
sub merged_requirements {
my $self = shift;
my $reqs = CPAN::Meta::Requirements->new;
for my $prereq (@{$self->{prereqs}}) {
$reqs->add_string_requirement($prereq->module, $prereq->requirement->version);
}
$reqs;
}
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}};
}
sub feature {
my($self, $identifier) = @_;
my $data = $self->{features}{$identifier}
or Carp::croak("Unknown feature '$identifier'");
my $prereqs = $self->build_cpan_meta($identifier);
CPAN::Meta::Feature->new($identifier, {
description => $data->{description},
prereqs => $prereqs->as_string_hash,
});
}
1;
|