blib/lib/CPAN/Reporter/PrereqCheck.pm

filter: Statementstmt 98.1% 103 / 105 Branchbran 88.7% 55 / 62 Conditioncond 66.6% 10 / 15 MC/DCmcdc 40.0% 4 / 10 Subroutinesub 100% 7 / 7 Podpod n/a totaltotal 89.9% 179 / 199 CC 40 SCAR 31.2
CC
40
Cov
92%
_run
30.5
_try_load
11.0
BEGIN
1.0
CRAP 22.6
↑ Summary blib/lib/CPAN/Reporter.pm »
1 59 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
2 package CPAN::Reporter::PrereqCheck;
3  
4 35 our $VERSION = '1.2019';
5  
6 47 ▶use ExtUtils::MakeMaker 6.36;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 47 ▶use File::Spec;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 47 ▶use CPAN::Version;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 35 ▶_run() if ! caller();
Branch: 1 branch
BranchTrueFalseTotal
unless caller() 0 35 35
11  
12 sub _run {
13 14 ▶ my %saw_mod;
Subroutine _run: called CC=30 SCAR=34.2
14 # read module and prereq string from STDIN
15 # do this as early as possible: https://github.com/cpan-testers/CPAN-Reporter/issues/20
16 my @modules;
17 14 ▶ while ( <> ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined($_ = readline ARGV)) 170 14 184
18 158 push @modules, $_;
19 }
20 14 local *DEVNULL;
21 14 open DEVNULL, ">" . File::Spec->devnull; ## no critic
22 # ensure actually installed, not ./inc/... or ./t/..., etc.
23 14 local @INC = grep { $_ ne '.' } @INC;
24 14 for (@modules) {
25 158 m/^(\S+)\s+([^\n]*)/;
26 158 my ($mod, $need) = ($1, $2);
27 158 ▶ die "Couldn't read module for '$_'" unless $mod;
Branch: 1 branch
BranchTrueFalseTotal
unless $mod 0 158 158
28 158 ▶ $need = 0 if not defined $need;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $need 0 158 158
29  
30 # only evaluate a module once
31 158 ▶ next if $saw_mod{$mod}++;
Branch: 1 branch
BranchTrueFalseTotal
if $saw_mod{$mod}++ 1 157 158
32  
33 # get installed version from file with EU::MM
34 157 my($have, $inst_file, $dir, @packpath);
35 157 ▶ if ( $mod eq "perl" ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($mod eq 'perl') { } 5 152 157
36 5 $have = $];
37 }
38 else {
39 152 @packpath = split( /::/, $mod );
40 152 $packpath[-1] .= ".pm";
41 152 ▶ if (@packpath == 1 && $packpath[0] eq "readline.pm") {
Branch: 1 branch
BranchTrueFalseTotal
if (@packpath == 1 and $packpath[0] eq "readline.pm") 0 152 152
Condition66%2/3
@packpath == 1 and $packpath[0] eq "readline.pm"
!ll&&!rl&&r
125270
MC/DC0%0/2
@packpath == 1 and $packpath[0] eq "readline.pm"
@packpath == 1 $packpath[0] eq "readline.pm"
Truth table66%2/3
A and B
A= @packpath == 1B= $packpath[0] eq "readline.pm"
ABresult
0X0
100
111
42 0 unshift @packpath, "Term", "ReadLine"; # historical reasons
43 }
44 INCDIR:
45 152 foreach my $dir (@INC) {
46 874 my $pmfile = File::Spec->catfile($dir,@packpath);
47 874 ▶ if (-f $pmfile){
Branch: 1 branch
BranchTrueFalseTotal
if (-f $pmfile) 130 744 874
48 130 $inst_file = $pmfile;
49 130 last INCDIR;
50 }
51 }
52  
53 # get version from file or else report missing
54 152 ▶ if ( defined $inst_file ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $inst_file) { } 130 22 152
55 130 $have = my $preliminary_version = MM->parse_version($inst_file);
56 130 ▶ $preliminary_version = "0" if ! defined $preliminary_version || $preliminary_version eq 'undef';
Branch: 1 branch
BranchTrueFalseTotal
if not defined $preliminary_version or $preliminary_version eq "undef" 5 125 130
Condition66%2/3
not defined $preliminary_version or $preliminary_version eq "undef"
l!l&&r!l&&!r
05125
MC/DC50%1/2
not defined $preliminary_version or $preliminary_version eq "undef"
not defined $preliminary_version $preliminary_version eq "undef"
Truth table66%2/3
not(A) or B
A= not defined $preliminary_versionB= $preliminary_version eq "undef"
ABresult
1X1
011
000
57 # report broken if it can't be loaded
58 # "select" to try to suppress spurious newlines
59 130 select DEVNULL; ## no critic
60 130 ▶ if ( ! _try_load( $mod, $preliminary_version ) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (_try_load($mod, $preliminary_version)) 4 126 130
61 4 select STDOUT; ## no critic
62 4 print "$mod 0 broken\n";
63 4 next;
64 }
65 # Now the module is loaded: if MM->parse_version previously failed to
66 # get the version, then we can now look at the value of the $VERSION
67 # variable.
68 126 ▶ if (! defined $have || $have eq 'undef') {
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $have or $have eq "undef") 5 121 126
Condition66%2/3
not defined $have or $have eq "undef"
l!l&&r!l&&!r
05121
MC/DC50%1/2
not defined $have or $have eq "undef"
not defined $have $have eq "undef"
Truth table66%2/3
not(A) or B
A= not defined $haveB= $have eq "undef"
ABresult
1X1
011
000
69 47 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
70 5 my $mod_version = ${$mod.'::VERSION'};
71 5 ▶ if (defined $mod_version) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $mod_version) { } 1 4 5
72 1 $have = $mod_version;
73 } else {
74 4 $have = 0; # fallback
75 }
76 }
77 126 select STDOUT; ## no critic
78 }
79 else {
80 22 print "$mod 0 n/a\n";
81 22 next;
82 }
83 }
84  
85 # complex requirements are comma separated
86 131 my ( @requirements ) = split /\s*,\s*/, $need;
87  
88 131 my $passes = 0;
89 RQ:
90 131 for my $rq (@requirements) {
91 143 ▶ if ($rq =~ s|>=\s*||) {
Branch: 5 branches
BranchTrueFalseTotal
if ($rq =~ s/>=\s*//) { } 9 134 143
elsif ($rq =~ s/>\s*//) { } 5 129 134
elsif ($rq =~ s/!=\s*//) { } 9 120 129
elsif ($rq =~ s/<=\s*//) { } 5 115 120
elsif ($rq =~ s/<\s*//) { } 9 106 115
92 # no-op -- just trimmed string
93 } elsif ($rq =~ s|>\s*||) {
94 5 ▶ if (CPAN::Version->vgt($have,$rq)){
Branch: 1 branch
BranchTrueFalseTotal
if ("CPAN::Version"->vgt($have, $rq)) 0 5 5
95 0 $passes++;
96 }
97 5 next RQ;
98 } elsif ($rq =~ s|!=\s*||) {
99 9 ▶ if (CPAN::Version->vcmp($have,$rq)) {
Branch: 1 branch
BranchTrueFalseTotal
if ("CPAN::Version"->vcmp($have, $rq)) 1 8 9
100 1 $passes++; # didn't match
101 }
102 9 next RQ;
103 } elsif ($rq =~ s|<=\s*||) {
104 5 ▶ if (! CPAN::Version->vgt($have,$rq)){
Branch: 1 branch
BranchTrueFalseTotal
unless ("CPAN::Version"->vgt($have, $rq)) 5 0 5
105 5 $passes++;
106 }
107 5 next RQ;
108 } elsif ($rq =~ s|<\s*||) {
109 9 ▶ if (CPAN::Version->vlt($have,$rq)){
Branch: 1 branch
BranchTrueFalseTotal
if ("CPAN::Version"->vlt($have, $rq)) 5 4 9
110 5 $passes++;
111 }
112 9 next RQ;
113 }
114 # if made it here, then it's a normal >= comparison
115 115 ▶ if (! CPAN::Version->vlt($have, $rq)){
Branch: 1 branch
BranchTrueFalseTotal
unless ("CPAN::Version"->vlt($have, $rq)) 111 4 115
116 111 $passes++;
117 }
118 }
119 131 ▶ my $ok = $passes == @requirements ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$passes == @requirements ? : 110 21 131
120 131 print "$mod $ok $have\n"
121 }
122 14 return;
123 }
124  
125 sub _try_load {
126 136 ▶ my ($module, $have) = @_;
Subroutine _try_load: called CC=11 SCAR=24.0
127  
128 136 my @do_not_load = (
129 # should not be loaded directly
130 qw/Term::ReadLine::Perl Term::ReadLine::Gnu MooseX::HasDefaults Readonly::XS
131 POE::Loop::Event SOAP::Constants
132 Moose::Meta::TypeConstraint::Parameterizable Moose::Meta::TypeConstraint::Parameterized/,
133 'Devel::Trepan', #"require Enbugger; require Devel::Trepan;" starts debugging session
134 'Test::BDD::Cucumber::Loader', #by doing something to Test::Builder breaks Test::SharedFork and any module that uses it
135  
136 #removed modules, they still exist but die
137 qw/Pegex::Mo YAML::LibYAML Params::CheckCompiler/,
138  
139 #have additional prereqs
140 qw/Log::Dispatch::Email::MailSender RDF::NS::Trine Plack::Handler::FCGI Web::Scraper::LibXML
141 DBIx::Class::EncodedColumn::Crypt::Eksblowfish::Bcrypt/,
142  
143 #modify @INC. 'lib' appearing in @INC will prevent correct
144 #checking of modules with XS part, for ex. List::Util
145 qw/ExtUtils::ParseXS ExtUtils::ParseXS::Utilities/,
146
147 #require special conditions to run
148 qw/mylib Test::YAML Cache::Reddit Dist::Zilla::Plugin::TestMLIncluder/,
149  
150 #print text to STDOUT which C::R::PC cannot intercept
151 qw/Test::Sys::Info Test::Subs/,
152  
153 #do not return true value
154 qw/perlsecret Alt::Crypt::RSA::BigInt/,
155  
156 #Try::Tiny::Tiny and modules that use it conflict with several modules
157 'Try::Tiny::Tiny',
158 'Date::Lectionary::Time',
159 );
160  
161 136 my %loading_conflicts = (
162 'signatures' => ['Catalyst'],
163 'Dancer::Plugin::FlashMessage' => ['Dancer::Plugin::FlashNote'],
164 'Dancer::Plugin::FlashNote' => ['Dancer::Plugin::FlashMessage'],
165 'Dancer::Plugin::Mongoose' => ['Dancer::Plugin::DBIC'],
166 'Dancer::Plugin::DBIC' => ['Dancer::Plugin::Mongoose'],
167 'Test::Mock::LWP::UserAgent' => ['HTTP::Response'],
168 'Test::BDD::Cucumber::Loader' => ['Test::Exception', 'Test::MockObject', 'Test::SharedFork'], #works in different order
169 'Test::SharedFork' => ['threads'], #dies if $INC{'threads.pm'}
170 'Test::TCP' => ['threads'], #loads Test::SharedFork
171 'Test::Fake::HTTPD' => ['threads'], #loads Test::SharedFork
172 'Plack::Test::Suite' => ['threads'], #loads Test::SharedFork
173 #Note: Test::Perl::Critic and other modules load threads, so reordering will not help
174 'App::Sqitch' => ['Moose'], #has "no Moo::sification"
175 ); #modules that conflict with each other
176
177 136 my %load_before = (
178 'Tk::Font' => 'Tk',
179 'Tk::Widget' => 'Tk',
180 'Tk::Label' => 'Tk',
181 'Tk::Menubutton' => 'Tk',
182 'Tk::Entry' => 'Tk',
183 'Class::MOP::Class' => 'Class::MOP',
184 'Moose::Meta::TypeConstraint::Role' => 'Moose',
185 'Moose::Meta::TypeConstraint::Union' => 'Moose',
186 'Moose::Meta::Attribute::Native' => 'Class::MOP',
187 'Moose::Meta::Role::Attribute' => 'Class::MOP',
188 'Moose::Util::TypeConstraints' => 'Moose',
189 'Test::More::Hooks' => 'Test::More',
190 'Net::HTTP::Spore::Middleware::DefaultParams' => 'Net::HTTP::Spore::Meta::Method',
191 'Log::Log4perl::Filter' => 'Log::Log4perl',
192 'RDF::DOAP::Project' => 'RDF::Trine', #or other modules that use RDF::Trine will fail
193 'Win32::API::Type' => 'Win32::API',
194 'Dancer2::Plugin::DBIC' => 'Dancer2', #or later Strehler::API will fail
195 'Wx::AUI' => 'Wx',
196 'Dist::Zilla::Role::Tempdir' => 'Dist::Zilla', # or it would not be possible to check Dist::Zilla
197 'Pod::Perldoc::ToMan' => 'Pod::Perldoc',
198 );
199  
200 # M::I < 0.95 dies in require, so we can't check if it loads
201 # Instead we just pretend that it works
202 136 ▶ if ( $module eq 'Module::Install' && $have < 0.95 ) {
Branch: 4 branches
BranchTrueFalseTotal
if ($module eq 'Module::Install' and $have < 0.95) { } 1 135 136
elsif ($module eq 'Catalyst::DispatchType::Regex' and $have <= 5.90032) { } 1 134 135
elsif (grep {$_ eq $module;} @do_not_load) { } 6 128 134
elsif ($module =~ /^Acme::/) { } 1 127 128
Condition66%2/3
$module eq "Module::Install" and $have < "0.95"
!ll&&!rl&&r
13501
MC/DC50%1/2
$module eq "Module::Install" and $have < "0.95"
$module eq "Module::Install" $have < "0.95"
Truth table66%2/3
A and B
A= $module eq "Module::Install"B= $have < "0.95"
ABresult
0X0
100
111
203 1 return 1;
204 }
205 # circular dependency with Catalyst::Runtime, so this module
206 # does not depends on it, but still does not work without it.
207 ▶ elsif ( $module eq 'Catalyst::DispatchType::Regex' && $have <= 5.90032 ) {
Condition66%2/3
$module eq "Catalyst::DispatchType::Regex" and $have <= "5.90032"
!ll&&!rl&&r
13401
MC/DC50%1/2
$module eq "Catalyst::DispatchType::Regex" and $have <= "5.90032"
$module eq "Catalyst::DispatchType::Regex" $have <= "5.90032"
Truth table66%2/3
A and B
A= $module eq "Catalyst::DispatchType::Regex"B= $have <= "5.90032"
ABresult
0X0
100
111
208 1 return 1;
209 }
210 4020 elsif ( grep { $_ eq $module } @do_not_load ) {
211 6 return 1;
212 }
213 # loading Acme modules like Acme::Bleach can do bad things,
214 # so never try to load them; just pretend that they work
215 elsif( $module =~ /^Acme::/ ) {
216 1 return 1;
217 }
218  
219 127 ▶ if ( exists $loading_conflicts{$module} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $loading_conflicts{$module}) 1 126 127
220 1 foreach my $mod1 ( @{ $loading_conflicts{$module} } ) {
221 1 my $file = "$mod1.pm";
222 1 $file =~ s{::}{/}g;
223 1 ▶ if (exists $INC{$file}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $INC{$file}) 1 0 1
224 1 return 1;
225 }
226 }
227 }
228  
229 126 ▶ if (exists $load_before{$module}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $load_before{$module}) 1 125 126
230 1 eval "require $load_before{$module};1;";
231 }
232  
233 126 my $file = "$module.pm";
234 126 $file =~ s{::}{/}g;
235  
236 126 return eval {require $file; 1}; ## no critic
237 }
238  
239 35 1;
240  
241 # ABSTRACT: Modulino for prerequisite tests
242  
243 __END__
↑ Summary blib/lib/CPAN/Reporter.pm »