Tangerine.pm

filter: Statementstmt 27.0% 50 / 185 Branchbran 0.0% 0 / 78 Conditioncond 0.0% 0 / 35 MC/DCmcdc 0.0% 0 / 20 Subroutinesub 55.1% 16 / 29 Podpod 0.0% 0 / 12 totaltotal 18.3% 66 / 359 CC 62 SCAR 53.1
CC
62
Cov
17%
run
506.0
init
342.0
sortmd
56.1
CRAP 202.2
↑ Summary Tangerine/Metadata.pm »
1 package App::Tangerine;
2 1 $App::Tangerine::VERSION = '0.22';
3 # ABSTRACT: Perl dependency metadata tool
4 1 ▶use 5.010;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 1 ▶use App::Tangerine::Metadata;
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 1 ▶use Archive::Extract;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 1 ▶use Cwd;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 1 ▶use File::Find::Rule;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 1 ▶use File::Find::Rule::Perl;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 1 ▶use File::Temp;
Subroutine BEGIN: called CC=1 SCAR=0.0
14 1 ▶use File::Spec;
Subroutine BEGIN: called CC=1 SCAR=0.0
15 1 ▶use Getopt::Long;
Subroutine BEGIN: called CC=1 SCAR=0.0
16 1 ▶use List::Compare;
Subroutine BEGIN: called CC=1 SCAR=0.0
17 1 ▶use MCE::Map;
Subroutine BEGIN: called CC=1 SCAR=0.0
18 1 ▶use Pod::Usage;
Subroutine BEGIN: called CC=1 SCAR=0.0
19 1 ▶use Tangerine;
Subroutine BEGIN: called CC=1 SCAR=0.0
20  
21 1 my %flags = (
22 jobs => 'auto',
23 mode => 'all',
24 );
25  
26 0 ▶sub init {
Subroutine init: not called CC=18 SCAR=58.3
Pod undocumented
27 GetOptions
28 all => \$flags{all},
29 compact => \$flags{compact},
30 diff => \$flags{diff},
31 files => \$flags{files},
32 'jobs=i' => \$flags{jobs},
33 help => \$flags{help},
34 'mode=s' => \$flags{mode},
35 0 verbose => \$flags{verbose};
36 0 my %p2uargs = (
37 -sections => 'SYNOPSIS|OPTIONS|EXAMPLES',
38 -verbose => 99);
39 0 ▶ unless (scalar(@ARGV)) {
Branch: 1 branch
BranchTrueFalseTotal
unless (scalar @ARGV) 0 0 0
40 0 pod2usage(-message => "Nothing to examine.\n",
41 -exitval => 1,
42 %p2uargs)
43 }
44 0 ▶ if ($flags{diff} && scalar(@ARGV) != 2) {
Branch: 1 branch
BranchTrueFalseTotal
if ($flags{"diff"} and scalar @ARGV != 2) 0 0 0
Condition0%0/3
$flags{"diff"} and scalar @ARGV != 2
!ll&&!rl&&r
000
MC/DC0%0/2
$flags{"diff"} and scalar @ARGV != 2
$flags{"diff"} scalar @ARGV != 2
Truth table0%0/3
A and B
A= $flags{"diff"}B= scalar @ARGV != 2
ABresult
0X0
100
111
45 0 pod2usage(-message => "The diff option requires two arguments.\n",
46 -exitval => 2,
47 %p2uargs)
48 }
49 0 ▶ if ($flags{diff} && !(-e $ARGV[0] && -e $ARGV[1])) {
Branch: 1 branch
BranchTrueFalseTotal
if ($flags{"diff"} and not -e $ARGV[0] && -e $ARGV[1]) 0 0 0
Condition0%0/6
$flags{"diff"} and not -e $ARGV[0] && -e $ARGV[1]
!ll&&!rl&&r
000
-e $ARGV[0] && -e $ARGV[1]
!ll&&!rl&&r
000
MC/DC0%0/3
$flags{"diff"} and not -e $ARGV[0] && -e $ARGV[1]
$flags{"diff"} -e $ARGV[0] -e $ARGV[1]
Truth table0%0/4
A and not(B && C)
A= $flags{"diff"}B= -e $ARGV[0]C= -e $ARGV[1]
ABCresult
0XX0
1110
10X1
1101
50 0 pod2usage(-message => "Cannot compute difference: No such file or directory.\n",
51 -exitval => 3,
52 %p2uargs)
53 }
54 0 ▶ if ($flags{mode} &&
Branch: 1 branch
BranchTrueFalseTotal
if ($flags{"mode"} and not $flags{"mode"} =~ /^(compile|u(se)?|runtime|r(eq)?|package|p(rov)?|a(ll)?)$/) 0 0 0
Condition0%0/3
$flags{"mode"} and not $flags{"mode"} =~ /^(compile|u(se)?|runtime|r(eq)?|package|p(rov)?|a(ll)?)$/
!ll&&!rl&&r
000
MC/DC0%0/2
$flags{"mode"} and not $flags{"mode"} =~ /^(compile|u(se)?|runtime|r(eq)?|package|p(rov)?|a(ll)?)$/
$flags{"mode"} not $flags{"mode"} =~ /^(compile|u(se)?|runtime|r(eq)?|package|p(rov)?|a(ll)?)$/
Truth table0%0/3
A and not(B)
A= $flags{"mode"}B= not $flags{"mode"} =~ /^(compile|u(se)?|runtime|r(eq)?|package|p(rov)?|a(ll)?)$/
ABresult
0X0
100
111
55 $flags{mode} !~ m/^(compile|u(se)?|runtime|r(eq)?|package|p(rov)?|a(ll)?)$/) {
56 0 pod2usage(-message => "Incorrect mode specified.\n",
57 -exitval => 4,
58 %p2uargs)
59 }
60 0 ▶ if ($flags{jobs} && $flags{jobs} !~ m/^(auto|\d+)$/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($flags{"jobs"} and not $flags{"jobs"} =~ /^(auto|\d+)$/) 0 0 0
Condition0%0/3
$flags{"jobs"} and not $flags{"jobs"} =~ /^(auto|\d+)$/
!ll&&!rl&&r
000
MC/DC0%0/2
$flags{"jobs"} and not $flags{"jobs"} =~ /^(auto|\d+)$/
$flags{"jobs"} not $flags{"jobs"} =~ /^(auto|\d+)$/
Truth table0%0/3
A and not(B)
A= $flags{"jobs"}B= not $flags{"jobs"} =~ /^(auto|\d+)$/
ABresult
0X0
100
111
61 0 pod2usage(-message => "The number of jobs must be a positive numeric value.\n",
62 -exitval => 5,
63 %p2uargs)
64 }
65 0 ▶ if ($flags{help}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($flags{"help"}) 0 0 0
66 0 pod2usage(%p2uargs);
67 }
68 0 ▶ if ($flags{compact} && $flags{mode} ne 'all') {
Branch: 1 branch
BranchTrueFalseTotal
if ($flags{"compact"} and $flags{"mode"} ne "all") 0 0 0
Condition0%0/3
$flags{"compact"} and $flags{"mode"} ne "all"
!ll&&!rl&&r
000
MC/DC0%0/2
$flags{"compact"} and $flags{"mode"} ne "all"
$flags{"compact"} $flags{"mode"} ne "all"
Truth table0%0/3
A and B
A= $flags{"compact"}B= $flags{"mode"} ne "all"
ABresult
0X0
100
111
69 0 print { *STDERR }
70 "Compact mode enabled. Setting mode to `all'...\n";
71 0 $flags{mode} = 'all'
72 }
73 0 ▶ if ($flags{compact} && $flags{files}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($flags{"compact"} and $flags{"files"}) 0 0 0
Condition0%0/3
$flags{"compact"} and $flags{"files"}
!ll&&!rl&&r
000
MC/DC0%0/2
$flags{"compact"} and $flags{"files"}
$flags{"compact"} $flags{"files"}
Truth table0%0/3
A and B
A= $flags{"compact"}B= $flags{"files"}
ABresult
0X0
100
111
74 0 print { *STDERR }
75 "Compact and files modes are incompatible. Ignoring files...\n";
76 $flags{files} = undef
77 0 }
78 MCE::Map::init {
79 0 ▶ max_workers => ($flags{jobs} // 'auto'),
Condition0%0/2
$flags{"jobs"} // "auto"
l!l
00
MC/DC0%0/1
$flags{"jobs"} // "auto"
$flags{"jobs"}
Truth table0%0/2
A
A= $flags{"jobs"}
Aresult
11
00
80 chunk_size => 1
81 };
82 0 ▶ adjustmode() if $flags{mode};
Branch: 1 branch
BranchTrueFalseTotal
if $flags{"mode"} 0 0 0
83 }
84  
85 0 ▶sub finish {
Subroutine finish: not called CC=1 SCAR=6.9
Pod undocumented
86 0 MCE::Map::finish;
87 }
88  
89 0 ▶sub adjustmode {
Subroutine adjustmode: not called CC=4 SCAR=30.0
Pod undocumented
90 0 ▶ $flags{mode} = 'u' if $flags{mode} =~ m/^(compile|u(se)?)$/;
Branch: 1 branch
BranchTrueFalseTotal
if $flags{"mode"} =~ /^(compile|u(se)?)$/ 0 0 0
91 0 ▶ $flags{mode} = 'r' if $flags{mode} =~ m/^(runtime|r(eq)?)$/;
Branch: 1 branch
BranchTrueFalseTotal
if $flags{"mode"} =~ /^(runtime|r(eq)?)$/ 0 0 0
92 0 ▶ $flags{mode} = 'p' if $flags{mode} =~ m/^(package|p(rov)?)$/;
Branch: 1 branch
BranchTrueFalseTotal
if $flags{"mode"} =~ /^(package|p(rov)?)$/ 0 0 0
93 }
94  
95
96 0 ▶sub analyze {
Subroutine analyze: not called CC=1 SCAR=6.9
Pod undocumented
97 0 ▶ mce_map {
Subroutine __ANON__: not called CC=4 SCAR=30.0
98 0 my @meta;
99 0 my $file = $_;
100 0 my $scanner = Tangerine->new(file => $file, mode => $flags{mode});
101 0 $scanner->run;
102 0 my %metameta = (
103 p => $scanner->provides,
104 c => $scanner->uses,
105 r => $scanner->requires
106 );
107 0 for my $metatype (keys %metameta) {
108 0 for my $mod (keys %{$metameta{$metatype}}) {
109 0 for my $occurence (@{$metameta{$metatype}->{$mod}}) {
110 0 push @meta, App::Tangerine::Metadata->new(
111 name => $mod,
112 type => $metatype,
113 file => $file,
114 line => $occurence->line,
115 version => $occurence->version
116 );
117 }
118 }
119 }
120 @meta
121 0 } @_
122 0 }
123  
124 0 ▶sub gatherfiles {
Subroutine gatherfiles: not called CC=5 SCAR=34.0
Pod undocumented
125 0 my @files;
126 my $findrule = $flags{all} ?
127 0 ▶ File::Find::Rule->file:
Branch: 1 branch
BranchTrueFalseTotal
$flags{'all'} ? : 0 0 0
128 File::Find::Rule->perl_file;
129 0 for my $arg (@_) {
130 0 ▶ if (-d $arg) {
Branch: 2 branches
BranchTrueFalseTotal
if (-d $arg) { } 0 0 0
elsif (-f $arg) { } 0 0 0
131 0 push @files, $findrule->in($arg);
132 } elsif (-f $arg) {
133 0 push @files, $arg
134 } else {
135 0 print { *STDERR } "Cannot access `$arg': No such file or directory\n"
136 }
137 }
138 @files
139 0 }
140  
141 0 ▶sub extract {
Subroutine extract: not called CC=2 SCAR=17.9
Pod undocumented
142 0 my ($archive, $destination) = @_;
143 0 my $ae = Archive::Extract->new(archive => $archive);
144 0 eval {
145 0 $ae->extract(to => $destination);
146 };
147 0 ▶ if ($@) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 0 0
148 0 print { *STDERR } "Failed to extract `$archive' to `$destination'.";
149 0 return;
150 }
151 0 return $ae->files;
152 }
153  
154 0 ▶sub analyzedir {
Subroutine analyzedir: not called CC=1 SCAR=6.9
Pod undocumented
155 0 my $dir = shift;
156 0 my $olddir = getcwd();
157 0 chdir $dir;
158 0 my @meta = analyze(gatherfiles(File::Spec->canonpath('./')));
159 0 chdir $olddir;
160 return @meta
161 0 }
162  
163 0 ▶sub analyzearchive {
Subroutine analyzearchive: not called CC=3 SCAR=24.8
Pod undocumented
164 0 my $archive = shift;
165 0 my $olddir = getcwd();
166 0 my $tmpdir = File::Temp->newdir('tangerine-XXXXXX',
167 DIR => File::Spec->tmpdir());
168 0 ▶ my $files = extract($archive, $tmpdir->dirname) or exit 100;
Branch: 1 branch
BranchTrueFalseTotal
my $files = extract($archive, $tmpdir->dirname) or exit 100 0 0 0
169 0 my $newdir = File::Spec->catdir($tmpdir->dirname, $files->[0]);
170 0 ▶ $newdir = (File::Spec->splitpath($newdir))[1] if -f $newdir;
Branch: 1 branch
BranchTrueFalseTotal
if -f $newdir 0 0 0
171 0 chdir $newdir;
172 0 my @meta = analyze(gatherfiles(File::Spec->canonpath('./')));
173 0 chdir $olddir;
174 return @meta
175 0 }
176  
177 0 ▶sub run {
Subroutine run: not called CC=22 SCAR=62.3
Pod undocumented
178 0 init();
179 0 ▶ if ($flags{diff}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($flags{'diff'}) { } 0 0 0
180 0 my (@m1, @m2);
181 0 ▶ @m1 = -d $ARGV[0] ? analyzedir($ARGV[0]) : analyzearchive($ARGV[0]);
Branch: 1 branch
BranchTrueFalseTotal
-d $ARGV[0] ? : 0 0 0
182 0 ▶ @m2 = -d $ARGV[1] ? analyzedir($ARGV[1]) : analyzearchive($ARGV[1]);
Branch: 1 branch
BranchTrueFalseTotal
-d $ARGV[1] ? : 0 0 0
183 0 my $lc = List::Compare->new(\@m1, \@m2);
184 0 @m1 = map { assemblemd($_) } $lc->get_unique;
185 0 @m2 = map { assemblemd($_) } $lc->get_complement;
186 0 my @files;
187 {
188 0 my %tmpfiles;
189 0 $tmpfiles{$_->file} = 1 for (@m1, @m2);
190 0 @files = keys %tmpfiles
191 }
192 0 for my $file (sort @files) {
193 0 print $file."\n";
194 0 for (sortmd(undef, @m1)) {
195 0 ▶ print "\t- ".
Branch: 2 branches
BranchTrueFalseTotal
if $_->file eq $file 0 0 0
$_->version ? : 0 0 0
196 formattype($_->type).
197 ' '.$_->name.
198 ($_->version ? ' ['.$_->version.']' : '').
199 "\n"
200 if $_->file eq $file
201 }
202 0 for (sortmd(undef, @m2)) {
203 0 ▶ print "\t+ ".
Branch: 2 branches
BranchTrueFalseTotal
if $_->file eq $file 0 0 0
$_->version ? : 0 0 0
204 formattype($_->type).
205 ' '.$_->name.
206 ($_->version ? ' ['.$_->version.']' : '').
207 "\n"
208 if ($_->file eq $file);
209 }
210 }
211 } else {
212 0 my @meta = analyze(gatherfiles(@ARGV));
213 0 ▶ if ($flags{files}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($flags{'files'}) { } 0 0 0
214 0 my $lastfile = '';
215 0 for my $md (sortmd('file', @meta)) {
216 0 ▶ if ($md->file ne $lastfile) {
Branch: 1 branch
BranchTrueFalseTotal
if ($md->file ne $lastfile) 0 0 0
217 0 print $md->file."\n";
218 0 $lastfile = $md->file
219 }
220 0 ▶ print "\t".
Branch: 1 branch
BranchTrueFalseTotal
$md->version ? : 0 0 0
221 formattype($md->type).
222 ' '.$md->name.
223 ' [#'.$md->line.']'.
224 ($md->version ? ' [v'.$md->version.']' : '').
225 "\n";
226 }
227 } else {
228 0 my $lastname = '';
229 0 my $skip = '';
230 0 for my $md (sortmd('name', @meta)) {
231 0 ▶ next if $md->name eq $skip;
Branch: 1 branch
BranchTrueFalseTotal
if $md->name eq $skip 0 0 0
232 0 ▶ if ($md->name ne $lastname) {
Branch: 1 branch
BranchTrueFalseTotal
if ($md->name ne $lastname) 0 0 0
233 0 $lastname = $md->name;
234 0 ▶ if ($flags{compact} && $md->type eq 'p') {
Branch: 1 branch
BranchTrueFalseTotal
if ($flags{"compact"} and $md->type eq "p") 0 0 0
Condition0%0/3
$flags{"compact"} and $md->type eq "p"
!ll&&!rl&&r
000
MC/DC0%0/2
$flags{"compact"} and $md->type eq "p"
$flags{"compact"} $md->type eq "p"
Truth table0%0/3
A and B
A= $flags{"compact"}B= $md->type eq "p"
ABresult
0X0
100
111
235 0 $skip = $md->name;
236 next
237 0 }
238 0 print $md->name."\n";
239 }
240 0 ▶ print "\t".
Branch: 1 branch
BranchTrueFalseTotal
$md->version ? : 0 0 0
241 formattype($md->type).
242 ' '.$md->file.
243 ':'.$md->line.
244 ($md->version ? ' [v'.$md->version.']' : '').
245 "\n";
246 }
247 }
248 }
249 0 finish();
250 }
251  
252 0 ▶sub formattype {
Subroutine formattype: not called CC=4 SCAR=30.0
Pod undocumented
253 0 my $type = shift;
254 0 ▶ return 'PACKAGE' if $type eq 'p';
Branch: 1 branch
BranchTrueFalseTotal
if $type eq "p" 0 0 0
255 0 ▶ return 'COMPILE' if $type eq 'c';
Branch: 1 branch
BranchTrueFalseTotal
if $type eq "c" 0 0 0
256 0 ▶ return 'RUNTIME' if $type eq 'r';
Branch: 1 branch
BranchTrueFalseTotal
if $type eq "r" 0 0 0
257 }
258  
259 0 ▶sub assemblemd {
Subroutine assemblemd: not called CC=1 SCAR=6.9
Pod undocumented
260 0 my ($t, $n, $v, $f) = split /\0/, shift;
261 0 App::Tangerine::Metadata->new(type => $t, name => $n, version => $v, file => $f)
262 }
263  
264 0 ▶sub sortmd {
Subroutine sortmd: not called CC=8 SCAR=40.3
Pod undocumented
265 0 my $by = shift;
266 1 ▶ no warnings 'uninitialized';
Subroutine BEGIN: called CC=1 SCAR=0.0
267 sort {
268 0 my (@first, @second);
269 0 ▶ if ($by eq 'name') {
Branch: 2 branches
BranchTrueFalseTotal
if ($by eq 'name') { } 0 0 0
elsif ($by eq 'file') { } 0 0 0
270 0 $first[0] = lc($a->name);
271 0 $first[1] = lc($b->name);
272 0 $second[0] = lc($a->file);
273 0 $second[1] = lc($b->file)
274 } elsif ($by eq 'file') {
275 0 $first[0] = lc($a->file);
276 0 $first[1] = lc($b->file);
277 0 $second[0] = lc($a->name);
278 0 $second[1] = lc($b->name)
279 }
280 0 ▶ $first[0] cmp $first[1] ||
Branch: 2 branches
BranchTrueFalseTotal
$a->type eq 'p' ? : 0 0 0
$b->type eq 'p' ? : 0 0 0
Condition0%0/9
$first[0] cmp $first[1] || ($a->type eq 'p' ? -1 : ($b->type eq 'p' ? 1 : $a->type cmp $b->type)) || $second[0] cmp $second[1] || $a->line <=> $b->line
l!l&&r!l&&!r
000
$first[0] cmp $first[1] or $a->type eq "p" ? -1 : ($b->type eq "p" ? 1 : $a->type cmp $b->type) or $second[0] cmp $second[1]
l!l&&r!l&&!r
000
$first[0] cmp $first[1] or $a->type eq "p" ? -1 : ($b->type eq "p" ? 1 : $a->type cmp $b->type)
l!l&&r!l&&!r
000
MC/DC0%0/4
$first[0] cmp $first[1] || ($a->type eq 'p' ? -1 : ($b->type eq 'p' ? 1 : $a->type cmp $b->type)) || $second[0] cmp $second[1] || $a->line <=> $b->line
$first[0] cmp $first[1] $a->type eq "p" ? -1 : ($b->type eq "p" ? 1 : $a->type cmp $b->type) $second[0] cmp $second[1] $a->line <=> $b->line
Truth table0%0/5
A or B or C || D
A= $first[0] cmp $first[1]B= $a->type eq "p" ? -1 : ($b->type eq "p" ? 1 : $a->type cmp $b->type)C= $second[0] cmp $second[1]D= $a->line <=> $b->line
ABCDresult
1XXX1
01XX1
001X1
00011
00000
281 ($a->type eq 'p' ? -1 :
282 ($b->type eq 'p' ? 1 :
283 $a->type cmp $b->type)) ||
284 $second[0] cmp $second[1] ||
285 $a->line <=> $b->line
286 } @_
287 }
288  
289 1 1;
290  
291 __END__
↑ Summary Tangerine/Metadata.pm »