blib/lib/App/findeps.pm

filter: Statementstmt 91.5% 140 / 153 Branchbran 74.5% 79 / 106 Conditioncond 76.0% 38 / 50 MC/DCmcdc 67.7% 21 / 31 Subroutinesub 95.0% 19 / 20 Podpod 0.0% 0 / 5 totaltotal 81.3% 297 / 365 CC 72 SCAR 34.4
CC
72
Cov
83%
scan
46.6
scanDir
42.0
scan_line
24.6
CRAP 31.3
↑ Summary script/findeps »
1 package App::findeps;
2  
3 25 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 25 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 25 ▶use feature qw(state);
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 25 our $VERSION = "0.13";
8  
9 25 ▶use Carp qw(carp croak);
Subroutine BEGIN: called CC=1 SCAR=0.0
10 25 ▶use ExtUtils::Installed;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 25 ▶use List::Util qw(first);
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13 25 ▶use Module::CoreList;
Subroutine BEGIN: called CC=1 SCAR=0.0
14 25 ▶use Directory::Iterator;
Subroutine BEGIN: called CC=1 SCAR=0.0
15  
16 25 our $Upgrade = 0;
17 25 our $myLib = 'lib';
18 25 our $toCpanfile = 0;
19 25 my $qr4ext = qr/\w+\.(p[ml]|t|cgi|psgi)$/;
20 25 my $qr4name = qr/[a-zA-Z][a-zA-Z\d]+(?:::[a-zA-Z\d]+){0,}/;
21  
22 0 ▶sub scanDir { # To Do
Subroutine scanDir: not called CC=6 SCAR=37.4
Pod undocumented
23 0 ▶ my $dir = shift || $myLib || 'lib';
Condition0%0/5
shift() || $App::findeps::myLib || 'lib'
l!l
00
shift() or $App::findeps::myLib
l!l&&r!l&&!r
000
MC/DC0%0/2
shift() || $App::findeps::myLib || 'lib'
shift() $App::findeps::myLib
Truth table0%0/3
A or B
A= shift()B= $App::findeps::myLib
ABresult
1X1
011
000
24 0 ▶ die "$dir is not a directory" unless -d $dir;
Branch: 1 branch
BranchTrueFalseTotal
unless -d $dir 0 0 0
25  
26 0 my @list = ();
27 0 my $list = Directory::Iterator->new($dir);
28 0 ▶ while ( $list->next ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($list->next) 0 0 0
29 0 my $file = $list->get;
30 0 ▶ next unless $file =~ /\.p[lm]$/;
Branch: 1 branch
BranchTrueFalseTotal
unless $file =~ /\.p[lm]$/ 0 0 0
31 0 scan( file => $file, list => \@list );
32 }
33 0 return @list;
34 }
35  
36 25 ▶sub scan {
Subroutine scan: called CC=45 SCAR=38.4
Pod undocumented
37 25 my %args = @_;
38 25 my %pairs;
39 25 ▶ while ( my $file = shift @{ $args{files} } ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $file = shift @{$args{"files"};}) 25 25 50
40 25 ( my $ext = $file ) =~ $qr4ext;
41 25 ▶ warn "Invalid extension was set: $ext" unless $1;
Branch: 1 branch
BranchTrueFalseTotal
unless $1 0 25 25
42 25 ▶ open my $fh, '<', $file or die "Can't open < $file: $!";
Branch: 1 branch
BranchTrueFalseTotal
open my $fh, "<", $file or die "Can't open < ${file}: $!" 25 0 25
43 25 ▶ while (<$fh>) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined($_ = readline $fh)) 381 24 405
44 381 chomp;
45 381 ▶ next unless defined $_;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $_ 0 381 381
46 381 ▶ last if /^__(?:END|DATA)__$/;
Branch: 1 branch
BranchTrueFalseTotal
if /^__(?:END|DATA)__$/ 1 380 381
47 380 state( $pod, $here, $eval );
48 380 ▶ next if $pod and $_ ne '=cut';
Branch: 1 branch
BranchTrueFalseTotal
if $pod and $_ ne "=cut" 31 349 380
Condition100%3/3
$pod and $_ ne "=cut"
!ll&&!rl&&r
347231
MC/DC100%2/2
$pod and $_ ne "=cut"
$pod $_ ne "=cut"
Truth table100%3/3
A and B
A= $podB= $_ ne "=cut"
ABresult
0X0
100
111
49 349 ▶ next if $here and $_ ne $here;
Branch: 1 branch
BranchTrueFalseTotal
if $here and $_ ne $here 17 332 349
Condition100%3/3
$here and $_ ne $here
!ll&&!rl&&r
328417
MC/DC100%2/2
$here and $_ ne $here
$here $_ ne $here
Truth table100%3/3
A and B
A= $hereB= $_ ne $here
ABresult
0X0
100
111
50 332 ▶ if ( !$pod and /^=(\w+)/ ) {
Branch: 2 branches
BranchTrueFalseTotal
if (not $pod and /^=(\w+)/) { } 2 330 332
elsif ($pod and $_ eq '=cut') { } 2 656 658
Condition100%3/3
not $pod and /^=(\w+)/
!ll&&!rl&&r
23282
MC/DC100%2/2
not $pod and /^=(\w+)/
not $pod /^=(\w+)/
Truth table100%3/3
not(A) and B
A= not $podB= /^=(\w+)/
ABresult
0X0
100
111
51 2 $pod = $1;
52 2 next;
53 ▶ } elsif ( $pod and $_ eq '=cut' ) {
Condition66%2/3
$pod and $_ eq "=cut"
!ll&&!rl&&r
32802
MC/DC50%1/2
$pod and $_ eq "=cut"
$pod $_ eq "=cut"
Truth table66%2/3
A and B
A= $podB= $_ eq "=cut"
ABresult
0X0
100
111
54 2 undef $pod;
55 2 next;
56 }
57 328 ▶ if ( !$here and my @catch = /(?:<<(['"])?(\w+)\1?){1,}/g ) {
Branch: 2 branches
BranchTrueFalseTotal
if (not $here and my(@catch) = /(?:<<(['"])?(\w+)\1?){1,}/g) { } 4 324 328
elsif ($here and $_ eq $here) { } 4 640 644
Condition100%3/3
not $here and my(@catch) = /(?:<<(['"])?(\w+)\1?){1,}/g
!ll&&!rl&&r
43204
MC/DC100%2/2
not $here and my(@catch) = /(?:<<(['"])?(\w+)\1?){1,}/g
not $here my(@catch) = /(?:<<(['"])?(\w+)\1?){1,}/g
Truth table100%3/3
not(A) and B
A= not $hereB= my(@catch) = /(?:<<(['"])?(\w+)\1?){1,}/g
ABresult
0X0
100
111
58 4 $here = $catch[-1];
59 4 next;
60 ▶ } elsif ( $here and $_ eq $here ) {
Condition66%2/3
$here and $_ eq $here
!ll&&!rl&&r
32004
MC/DC50%1/2
$here and $_ eq $here
$here $_ eq $here
Truth table66%2/3
A and B
A= $hereB= $_ eq $here
ABresult
0X0
100
111
61 4 undef $here;
62 4 next;
63 }
64 320 ▶ next if /^\s*#.*/;
Branch: 1 branch
BranchTrueFalseTotal
if /^\s*#.*/ 19 301 320
65 301 s/\s+#.*$//;
66 301 ▶ if ( !$eval and /eval\s*(['"{])$/ ) {
Branch: 3 branches
BranchTrueFalseTotal
if (not $eval and /eval\s*(['"{])$/) { } 3 298 301
elsif ($eval and /$eval(?:.*)?;$/) { } 3 295 298
elsif ($eval and /\b(require|use)\s+($qr4name)/) { } 3 583 586
Condition100%3/3
not $eval and /eval\s*(['"{])$/
!ll&&!rl&&r
72913
MC/DC100%2/2
not $eval and /eval\s*(['"{])$/
not $eval /eval\s*(['"{])$/
Truth table100%3/3
not(A) and B
A= not $evalB= /eval\s*(['"{])$/
ABresult
0X0
100
111
67 3 ▶ $eval = $1 eq '{' ? '}' : $1;
Branch: 1 branch
BranchTrueFalseTotal
$1 eq '{' ? : 1 2 3
68 ▶ } elsif ( $eval and /$eval(?:.*)?;$/ ) {
Condition100%3/3
$eval and /$eval(?:.*)?;$/
!ll&&!rl&&r
29143
MC/DC100%2/2
$eval and /$eval(?:.*)?;$/
$eval /$eval(?:.*)?;$/
Truth table100%3/3
A and B
A= $evalB= /$eval(?:.*)?;$/
ABresult
0X0
100
111
69 3 undef $eval;
70 3 next;
71 ▶ } elsif ( $eval and /\b(require|use)\s+($qr4name)/ ) {
Condition100%3/3
$eval and /\b(require|use)\s+($qr4name)/
!ll&&!rl&&r
29113
MC/DC100%2/2
$eval and /\b(require|use)\s+($qr4name)/
$eval /\b(require|use)\s+($qr4name)/
Truth table100%3/3
A and B
A= $evalB= /\b(require|use)\s+($qr4name)/
ABresult
0X0
100
111
72 3 warnIgnored( $2, $1, 'eval' );
73 }
74 298 ▶ next if $eval;
Branch: 1 branch
BranchTrueFalseTotal
if $eval 7 291 298
75  
76 291 ▶ if (/\buse\b/) {
Branch: 1 branch
BranchTrueFalseTotal
if (/\buse\b/) 85 206 291
77 85 scan_line( \%pairs, $_ );
78 85 next;
79 }
80  
81 206 state $if = 0;
82 206 ▶ if (/^\b(?:if|unless)\s*\(.*\)\s*{$/) {
Branch: 3 branches
BranchTrueFalseTotal
if (/^\b(?:if|unless)\s*\(.*\)\s*{$/) { } 8 198 206
elsif ($if > 0 and /^\s*}$/) { } 8 190 198
elsif ($if > 0 and /^\brequire\s+($qr4name)/) { } 0 365 365
83 8 $if++;
84 ▶ } elsif ( $if > 0 and /^\s*}$/ ) {
Condition100%3/3
$if > 0 and /^\s*}$/
!ll&&!rl&&r
175158
MC/DC100%2/2
$if > 0 and /^\s*}$/
$if > 0 /^\s*}$/
Truth table100%3/3
A and B
A= $if > 0B= /^\s*}$/
ABresult
0X0
100
111
85 8 $if--;
86 8 ▶ warn "something wrong to parse: $file" if $if < 0;
Branch: 1 branch
BranchTrueFalseTotal
if $if < 0 0 8 8
87 8 next;
88 ▶ } elsif ( $if > 0 and /^\brequire\s+($qr4name)/ ) {
Condition66%2/3
$if > 0 and /^\brequire\s+($qr4name)/
!ll&&!rl&&r
175150
MC/DC0%0/2
$if > 0 and /^\brequire\s+($qr4name)/
$if > 0 /^\brequire\s+($qr4name)/
Truth table66%2/3
A and B
A= $if > 0B= /^\brequire\s+($qr4name)/
ABresult
0X0
100
111
89 0 warnIgnored( 'require', $1, 'if' );
90 }
91 198 ▶ next unless /\b(require|use)\s+/;
Branch: 1 branch
BranchTrueFalseTotal
unless /\b(require|use)\s+/ 158 40 198
92 40 scan_line( \%pairs, $_ );
93 }
94 25 close $fh;
95 }
96 25 my $deps = {};
97 25 my @local = ();
98 25 my $list = Directory::Iterator->new($myLib)
99 ; # To Do: $myLib must be got from local::lib within plenv/PerlBrew
100 25 ▶ while ( $list->next ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($list->next) 52 25 77
101 52 my $file = $list->get;
102 52 ▶ next unless $file =~ s!\.pm$!!;
Branch: 1 branch
BranchTrueFalseTotal
unless $file =~ s/\.pm$// 0 52 52
103 52 $file =~ s!/!::!g;
104 52 push @local, $file;
105 }
106  
107 25 ▶ while ( my ( $name, $version ) = each %pairs ) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = each %pairs) 37 25 62
108 37 ▶ next if !defined $name;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $name 0 37 37
109 37 ▶ next if exists $deps->{$name};
Branch: 1 branch
BranchTrueFalseTotal
if exists $deps->{$name} 0 37 37
110 37 ▶ next if first { $_ eq $name } @local;
Subroutine __ANON__: called CC=1 SCAR=0.2
Branch: 1 branch
BranchTrueFalseTotal
if &first(sub { $_ eq $name; } , @local) 0 37 37
111 37 ▶ $deps->{$name} = $version if !defined $version or $Upgrade or $toCpanfile;
Branch: 1 branch
BranchTrueFalseTotal
if not defined $version or $App::findeps::Upgrade or $App::findeps::toCpanfile 28 9 37
Condition66%4/6
not defined $version or $App::findeps::Upgrade or $App::findeps::toCpanfile
l!l&&r!l&&!r
2809
not defined $version or $App::findeps::Upgrade
l!l&&r!l&&!r
2809
MC/DC33%1/3
not defined $version or $App::findeps::Upgrade or $App::findeps::toCpanfile
not defined $version $App::findeps::Upgrade $App::findeps::toCpanfile
Truth table50%2/4
not(A) or B or C
A= not defined $versionB= $App::findeps::UpgradeC= $App::findeps::toCpanfile
ABCresult
1XX1
01X1
0011
0000
112 }
113 25 return $deps;
114 }
115  
116 # subroutines #----#----#----#----#----#----#----#----#----#----#----#----#
117 25 my @pragmas = qw(
118 attributes autodie autouse
119 base bigint bignum bigrat blib bytes
120 charnames constant diagnostics encoding
121 feature fields filetest if integer less lib locale mro
122 open ops overload overloading parent re
123 sigtrap sort strict subs
124 threads threads::shared utf8 vars vmsish
125 warnings warnings::register
126 );
127  
128 125 ▶sub scan_line {
Subroutine scan_line: called CC=19 SCAR=32.0
Pod undocumented
129 125 my $pairs = shift;
130 125 local $_ = shift;
131 125 my @names = ();
132 125 ▶ return if /^\buse\s+v5(?:\.\d{2}){1,2}\s*;/; #ignore VERSION
Branch: 1 branch
BranchTrueFalseTotal
if /^\buse\s+v5(?:\.\d{2}){1,2}\s*;/ 0 125 125
133 125 ▶ return if /^\buse\s+5\.\d{3}(?:_\d{3})?;/; #ignore old version
Branch: 1 branch
BranchTrueFalseTotal
if /^\buse\s+5\.\d{3}(?:_\d{3})?;/ 0 125 125
134  
135 125 ▶ if (/use\s+(?:base|parent)\s+qw[\("']\s*((?:$qr4name\s*){1,})[\)"']/) {
Branch: 7 branches
BranchTrueFalseTotal
if (/use\s+(?:base|parent)\s+qw[\("']\s*((?:$qr4name\s*){1,})[\)"']/) { } 1 124 125
elsif (/use\s+(?:base|parent|autouse)\s+(['"])?($qr4name)\1?/) { } 6 118 124
elsif (/eval\s*(['"{])\s*(require|use)\s+($qr4name).*(?:\1|})/) { } 2 116 118
elsif (/(?:if|unless)\s+\(.*\)\s*\{.*require\s+($qr4name).*\}/ or /require\s+($qr4name)\s+(?:if|unless)\s+\(?.*\)?/) { } 10 106 116
elsif (/^\s*(?:require|use)\s+($qr4name)/) { } 102 4 106
elsif (m[^\s*require\s*(["'])((?:\./)?(?:\w+/){0,}$qr4name\.pm)\1]) { } 4 0 4
elsif (/^\s*(require|use)\s+(['"]?)(.*)\2/) { } 0 0 0
136 1 push @names, split /\s+/, $1;
137 } elsif (/use\s+(?:base|parent|autouse)\s+(['"])?($qr4name)\1?/) {
138 6 $names[0] = $2;
139 } elsif (/eval\s*(['"{])\s*(require|use)\s+($qr4name).*(?:\1|})/) {
140 2 warnIgnored( $3, $2, 'eval' );
141 ▶ } elsif ( /(?:if|unless)\s+\(.*\)\s*\{.*require\s+($qr4name).*\}/
Condition100%3/3
/(?:if|unless)\s+\(.*\)\s*\{.*require\s+($qr4name).*\}/ or /require\s+($qr4name)\s+(?:if|unless)\s+\(?.*\)?/
l!l&&r!l&&!r
64106
MC/DC100%2/2
/(?:if|unless)\s+\(.*\)\s*\{.*require\s+($qr4name).*\}/ or /require\s+($qr4name)\s+(?:if|unless)\s+\(?.*\)?/
/(?:if|unless)\s+\(.*\)\s*\{.*require\s+($qr4name).*\}/ /require\s+($qr4name)\s+(?:if|unless)\s+\(?.*\)?/
Truth table100%3/3
A or B
A= /(?:if|unless)\s+\(.*\)\s*\{.*require\s+($qr4name).*\}/B= /require\s+($qr4name)\s+(?:if|unless)\s+\(?.*\)?/
ABresult
1X1
011
000
142 or /require\s+($qr4name)\s+(?:if|unless)\s+\(?.*\)?/ )
143 {
144 10 warnIgnored( $1, 'require', 'if' );
145 } elsif (/^\s*(?:require|use)\s+($qr4name)/) {
146 102 $names[0] = $1;
147 } elsif (m!^\s*require\s*(["'])((?:\./)?(?:\w+/){0,}$qr4name\.pm)\1!) {
148 4 $names[0] = _name($2);
149 } elsif (/^\s*(require|use)\s+(['"]?)(.*)\2/) {
150 0 my $name = $3;
151 0 ▶ my $exists = ( -e "$myLib/$name" ) ? 'exists' : "does not exist in $myLib";
Branch: 1 branch
BranchTrueFalseTotal
-e "$App::findeps::myLib/$name" ? : 0 0 0
152 0 warn "just detected but not listed: $name($exists) $1d\n";
153 }
154 125 for my $name (@names) {
155 114 ▶ next unless defined $name;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $name 0 114 114
156 114 ▶ next if exists $pairs->{$name};
Branch: 1 branch
BranchTrueFalseTotal
if exists $pairs->{$name} 6 108 114
157 108 ▶ next if $name eq 'Plack::Builder';
Branch: 1 branch
BranchTrueFalseTotal
if $name eq "Plack::Builder" 0 108 108
158 108 ▶ next if first { $name eq $_ } @pragmas;
Subroutine __ANON__: called CC=1 SCAR=0.0
Branch: 1 branch
BranchTrueFalseTotal
if &first(sub { $name eq $_; } , @pragmas) 71 37 108
159 37 ▶ next if !$Upgrade and Module::CoreList->is_core($name);
Branch: 1 branch
BranchTrueFalseTotal
if not $App::findeps::Upgrade and "Module::CoreList"->is_core($name) 0 37 37
Condition33%1/3
not $App::findeps::Upgrade and "Module::CoreList"->is_core($name)
!ll&&!rl&&r
0370
MC/DC0%0/2
not $App::findeps::Upgrade and "Module::CoreList"->is_core($name)
not $App::findeps::Upgrade "Module::CoreList"->is_core($name)
Truth table33%1/3
not(A) and B
A= not $App::findeps::UpgradeB= "Module::CoreList"->is_core($name)
ABresult
0X0
100
111
160 37 $pairs->{$name} = get_version($name);
161 }
162 125 return %$pairs;
163 }
164  
165 37 ▶sub get_version {
Subroutine get_version: called CC=3 SCAR=11.0
Pod undocumented
166 37 my $name = shift;
167 37 my $installed = ExtUtils::Installed->new( skip_cwd => 1 );
168 37 ▶ my $module = first { $_ eq $name } $installed->modules();
Subroutine __ANON__: called CC=1 SCAR=0.0
169 37 my $version = eval { $installed->version($module) };
170 37 ▶ return $version if defined $version;
Branch: 1 branch
BranchTrueFalseTotal
if defined $version 0 37 37
171 25 ▶ eval "use lib '$myLib'; require $name" or return undef;
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Branch: 1 branch
BranchTrueFalseTotal
eval "use lib '$App::findeps::myLib'; require $name" or return undef 9 28 37
172 9 ▶ return eval "no strict 'subs';\$${name}::VERSION";
Subroutine BEGIN: called CC=1 SCAR=0.0
173 }
174  
175 15 ▶sub warnIgnored {
Subroutine warnIgnored: called CC=2 SCAR=7.0
Pod undocumented
176 15 my $name = shift;
177 15 my $func = shift;
178 15 my $cmd = shift;
179 15 ▶ warn "$name is ${func}d inside of '$cmd'\n" unless Module::CoreList->is_core($name);
Branch: 1 branch
BranchTrueFalseTotal
unless "Module::CoreList"->is_core($name) 15 0 15
180 }
181  
182 32 ▶sub _name {
Subroutine _name: called CC=2 SCAR=6.9
183 32 my $str = shift;
184 32 ▶ $str =~ s!/!::!g if $str =~ /\.pm$/;
Branch: 1 branch
BranchTrueFalseTotal
if $str =~ /\.pm$/ 4 28 32
185 32 $str =~ s!^lib::!!;
186 32 $str =~ s!\.pm$!!;
187 32 $str =~ s!^auto::(.+)::.*!$1!;
188 32 return $str;
189 }
190  
191 25 1;
192  
193 __END__
↑ Summary script/findeps »