blib/lib/Dist/Zilla/Prereqs.pm

filter: Statementstmt 100% 49 / 49 Branchbran 75.0% 3 / 4 Conditioncond 83.3% 5 / 6 MC/DCmcdc 66.6% 2 / 3 Subroutinesub 100% 12 / 12 Podpod 50.0% 1 / 2 totaltotal 94.7% 72 / 76 CC 9 SCAR 11.4
CC
9
Cov
97%
register_prereqs
6.0
sync_runtime_build_test_requires
4.0
BEGIN
1.0
CRAP 3.1
« blib/lib/Dist/Zilla/Plugin/FileFinder/ByName.pm ↑ Summary blib/lib/Dist/Zilla/Plugin/UploadToCPAN.pm »
1 package Dist::Zilla::Prereqs 6.040;
2 # ABSTRACT: the prerequisites of a Dist::Zilla distribution
3  
4 53 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 53 ▶use Dist::Zilla::Pragmas;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 53 ▶use MooseX::Types::Moose qw(Bool HashRef);
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 53 ▶use CPAN::Meta::Prereqs 2.120630; # add_string_requirement
Subroutine BEGIN: called CC=1 SCAR=0.0
11 53 ▶use String::RewritePrefix;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 53 ▶use CPAN::Meta::Requirements 2.121; # requirements_for_module
Subroutine BEGIN: called CC=1 SCAR=0.0
13  
14 53 ▶use namespace::autoclean;
Subroutine BEGIN: called CC=1 SCAR=0.0
15  
16 #pod =head1 DESCRIPTION
17 #pod
18 #pod Dist::Zilla::Prereqs is a subcomponent of Dist::Zilla. The C<prereqs>
19 #pod attribute on your Dist::Zilla object is a Dist::Zilla::Prereqs object, and is
20 #pod responsible for keeping track of the distribution's prerequisites.
21 #pod
22 #pod In fact, a Dist::Zilla::Prereqs object is just a thin layer over a
23 #pod L<CPAN::Meta::Prereqs> object, stored in the C<cpan_meta_prereqs> attribute.
24 #pod
25 #pod Almost everything this object does is proxied to the CPAN::Meta::Prereqs
26 #pod object, so you should really read how I<that> works.
27 #pod
28 #pod Dist::Zilla::Prereqs proxies the following methods to the CPAN::Meta::Prereqs
29 #pod object:
30 #pod
31 #pod =for :list
32 #pod * finalize
33 #pod * is_finalized
34 #pod * requirements_for
35 #pod * as_string_hash
36 #pod
37 #pod =cut
38  
39 has cpan_meta_prereqs => (
40 is => 'ro',
41 isa => 'CPAN::Meta::Prereqs',
42 init_arg => undef,
43 170 ▶ default => sub { CPAN::Meta::Prereqs->new },
Subroutine __ANON__: called CC=1 SCAR=0.0
44 53 handles => [ qw(
45 finalize
46 is_finalized
47 requirements_for
48 as_string_hash
49 ) ],
50 );
51  
52 # storing this is sort of gross, but MakeMaker winds up needing the same data
53 # anyway. -- xdg, 2013-10-22
54 # This does *not* contain configure requires, as MakeMaker explicitly should
55 # not have it in its fallback prereqs.
56 has merged_requires => (
57 is => 'ro',
58 isa => 'CPAN::Meta::Requirements',
59 init_arg => undef,
60 170 ▶ default => sub { CPAN::Meta::Requirements->new },
Subroutine __ANON__: called CC=1 SCAR=0.0
61 53 );
62  
63 #pod =method register_prereqs
64 #pod
65 #pod $prereqs->register_prereqs(%prereqs);
66 #pod
67 #pod $prereqs->register_prereqs(\%arg, %prereqs);
68 #pod
69 #pod This method adds new minimums to the prereqs object. If a hashref is the first
70 #pod arg, it may have entries for C<phase> and C<type> to indicate what kind of
71 #pod prereqs are being registered. (For more information on phase and type, see
72 #pod L<CPAN::Meta::Spec>.) For example, you might say:
73 #pod
74 #pod $prereqs->register_prereqs(
75 #pod { phase => 'test', type => 'recommends' },
76 #pod 'Test::Foo' => '1.23',
77 #pod 'XML::YZZY' => '2.01',
78 #pod );
79 #pod
80 #pod If not given, phase and type default to runtime and requires, respectively.
81 #pod
82 #pod =cut
83  
84 340 ▶sub register_prereqs {
Subroutine register_prereqs: called CC=6 SCAR=18.0
Pod documented
85 340 my $self = shift;
86 340 ▶ my $arg = ref($_[0]) ? shift(@_) : {};
Branch: 1 branch
BranchTrueFalseTotal
ref $_[0] ? : 340 0 340
87 340 my %prereq = @_;
88  
89 340 ▶ my $phase = $arg->{phase} || 'runtime';
Condition50%1/2
$arg->{'phase'} || 'runtime'
l!l
3400
MC/DC0%0/1
$arg->{'phase'} || 'runtime'
$arg->{'phase'}
Truth table50%1/2
A
A= $arg->{'phase'}
Aresult
11
00
90 340 ▶ my $type = $arg->{type} || 'requires';
Condition100%2/2
$arg->{'type'} || 'requires'
l!l
29347
MC/DC100%1/1
$arg->{'type'} || 'requires'
$arg->{'type'}
Truth table100%2/2
A
A= $arg->{'type'}
Aresult
11
00
91  
92 340 my $req = $self->requirements_for($phase, $type);
93  
94 340 ▶ while (my ($package, $version) = each %prereq) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = each %prereq) 823 340 1163
95 823 ▶ $req->add_string_requirement($package, $version || 0);
Condition100%2/2
$version || 0
l!l
283540
MC/DC100%1/1
$version || 0
$version
Truth table100%2/2
A
A= $version
Aresult
11
00
96 }
97  
98 340 return;
99 }
100  
101 152 ▶before 'finalize' => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
102 152 my ($self) = @_;
103 152 $self->sync_runtime_build_test_requires;
104 53 };
105  
106  
107 # this avoids a long-standing CPAN.pm bug that incorrectly merges runtime and
108 # "build" (build+test) requirements by ensuring requirements stay unified
109 # across all three phases
110 152 ▶sub sync_runtime_build_test_requires {
Subroutine sync_runtime_build_test_requires: called CC=4 SCAR=13.9
Pod undocumented
111 152 my $self = shift;
112  
113 # first pass: generated merged requirements
114 152 for my $phase ( qw/runtime build test/ ) {
115 456 my $req = $self->requirements_for($phase, 'requires');
116 456 $self->merged_requires->add_requirements( $req );
117 };
118  
119 # second pass: update from merged requirements
120 152 for my $phase ( qw/runtime build test/ ) {
121 456 my $req = $self->requirements_for($phase, 'requires');
122 456 for my $mod ( $req->required_modules ) {
123 225 $req->clear_requirement( $mod );
124 225 $req->add_string_requirement(
125 $mod => $self->merged_requires->requirements_for_module($mod)
126 );
127 }
128 }
129  
130 152 return;
131 }
132  
133 53 __PACKAGE__->meta->make_immutable;
134 53 1;
135  
136 __END__
« blib/lib/Dist/Zilla/Plugin/FileFinder/ByName.pm ↑ Summary blib/lib/Dist/Zilla/Plugin/UploadToCPAN.pm »