Plugin/RecommendedPrereqs.pm

filter: Statementstmt 100% 39 / 39 Branchbran 100% 8 / 8 Conditioncond 57.1% 4 / 7 MC/DCmcdc 25.0% 1 / 4 Subroutinesub 100% 6 / 6 Podpod 0.0% 0 / 1 totaltotal 89.2% 58 / 65 CC 11 SCAR 20.7
CC
11
Cov
94%
register_prereqs
11.1
BEGIN
1.0
BEGIN
1.0
CRAP 7.9
« Plugin/GitVersionCheckCJM.pm ↑ Summary Role/HashDumper.pm »
1 #---------------------------------------------------------------------
2 package Dist::Zilla::Plugin::RecommendedPrereqs;
3 #
4 # Copyright 2011 Christopher J. Madsen
5 #
6 # Author: Christopher J. Madsen <perl@cjmweb.net>
7 # Created: 31 Oct 2011
8 #
9 # This program is free software; you can redistribute it and/or modify
10 # it under the same terms as Perl itself.
11 #
12 # This program is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See either the
15 # GNU General Public License or the Artistic License for more details.
16 #
17 # ABSTRACT: Look for comments recommending prerequisites
18 #---------------------------------------------------------------------
19  
20 2 our $VERSION = '4.21';
21 # This file is part of Dist-Zilla-Plugins-CJM 6.000 (December 17, 2017)
22  
23  
24 2 ▶use 5.008;
Subroutine BEGIN: called CC=1 SCAR=0.0
25 2 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
26 2 with(
27 'Dist::Zilla::Role::PrereqSource',
28 'Dist::Zilla::Role::FileFinderUser' => {
29 default_finders => [ ':InstallModules', ':ExecFiles' ],
30 },
31 'Dist::Zilla::Role::FileFinderUser' => {
32 method => 'found_test_files',
33 finder_arg_names => [ 'test_finder' ],
34 default_finders => [ ':TestFiles' ],
35 },
36 );
37  
38 2 ▶use namespace::autoclean;
Subroutine BEGIN: called CC=1 SCAR=0.0
39  
40 #=====================================================================
41  
42 2 ▶use CPAN::Meta::Requirements ();
Subroutine BEGIN: called CC=1 SCAR=0.0
43 2 ▶use version ();
Subroutine BEGIN: called CC=1 SCAR=0.0
44  
45 sub register_prereqs
46 1 ▶{
Subroutine register_prereqs: called CC=11 SCAR=24.0
Pod undocumented
47 1 my $self = shift;
48  
49 1 my @sets = (
50 [ runtime => 'found_files' ],
51 [ test => 'found_test_files' ],
52 );
53  
54 1 my %runtime;
55  
56 1 for my $fileset (@sets) {
57 2 my ($phase, $method) = @$fileset;
58  
59 2 my %req = map { $_ => CPAN::Meta::Requirements->new } qw(RECOMMEND SUGGEST);
60  
61 2 my $files = $self->$method;
62  
63 2 foreach my $file (@$files) {
64 3 $self->log_debug("Checking " . $file->name);
65 3 my $content = $file->content;
66  
67 3 ▶ while ($content =~ /^ [ \t]* \# [ \t]* (RECOMMEND|SUGGEST) [ \t]+ PREREQ:
Branch: 1 branch
BranchTrueFalseTotal
if ($content =~ /^ [ \t]* \# [ \t]* (RECOMMEND|SUGGEST) [ \t]+ PREREQ: [ \t]* (\S+) (?: [ \t]+ (\S+) )?/gmx) 3 3 6
68 [ \t]* (\S+) (?: [ \t]+ (\S+) )?/mgx) {
69 3 ▶ $req{$1}->add_minimum($2, $3 || 0);
Condition100%2/2
$3 || 0
l!l
12
MC/DC100%1/1
$3 || 0
$3
Truth table100%2/2
A
A= $3
Aresult
11
00
70 }
71 } # end foreach $file
72  
73 # we're done, add what we've found
74 2 ▶ while (my ($type, $req) = each %req) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = each %req) 4 2 6
75 4 $req = $req->as_string_hash;
76  
77 4 ▶ if ($phase eq 'runtime') {
Branch: 1 branch
BranchTrueFalseTotal
if ($phase eq 'runtime') { } 2 2 4
78 2 $runtime{$type} = $req;
79 } else {
80 2 delete $req->{$_} for
81 2 ▶ grep { exists $req->{$_} and $runtime{$type}{$_} ge $req->{$_} }
Condition33%1/3
exists $req->{$_} && $runtime{$type}{$_} ge $req->{$_}
!ll&&!rl&&r
200
MC/DC0%0/2
exists $req->{$_} && $runtime{$type}{$_} ge $req->{$_}
exists $req->{$_} $runtime{$type}{$_} ge $req->{$_}
Truth table33%1/3
A && B
A= exists $req->{$_}B= $runtime{$type}{$_} ge $req->{$_}
ABresult
0X0
100
111
82 2 ▶ keys %{ $runtime{$type} || {} };
Condition50%1/2
$runtime{$type} || {}
l!l
20
MC/DC0%0/1
$runtime{$type} || {}
$runtime{$type}
Truth table50%1/2
A
A= $runtime{$type}
Aresult
11
00
83 }
84  
85 4 ▶ $self->zilla->register_prereqs({ phase => $phase, type => "\L${type}s" },
Branch: 1 branch
BranchTrueFalseTotal
if %$req 2 2 4
86 %$req) if %$req;
87 }
88 } # end foreach $fileset
89 } # end register_prereqs
90  
91 #=====================================================================
92 # Package Return Value:
93  
94 2 __PACKAGE__->meta->make_immutable;
95 2 1;
96  
97 __END__
« Plugin/GitVersionCheckCJM.pm ↑ Summary Role/HashDumper.pm »