Tangerine.pm

filter: Statementstmt 99.0% 99 / 100 Branchbran 72.7% 32 / 44 Conditioncond 44.1% 19 / 43 MC/DCmcdc 18.1% 4 / 22 Subroutinesub 100% 19 / 19 Podpod 71.4% 5 / 7 totaltotal 75.7% 178 / 235 CC 44 SCAR 38.7
CC
44
Cov
80%
run
70.1
new
2.0
__ANON__
2.0
CRAP 47.9
↑ Summary Tangerine/hook/if.pm »
1 package Tangerine;
2 15 $Tangerine::VERSION = '0.21';
3 # ABSTRACT: Examine perl files and report dependency metadata
4 15 ▶use 5.010;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 15 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 15 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 15 ▶use utf8;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 15 ▶use PPI;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 15 ▶use List::Util 1.33 qw(any none);
Subroutine BEGIN: called CC=1 SCAR=0.0
10 15 ▶use Scalar::Util qw(blessed);
Subroutine BEGIN: called CC=1 SCAR=0.0
11 15 ▶use Tangerine::Hook;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 15 ▶use Tangerine::Occurence;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 15 ▶use Tangerine::Utils qw(accessor addoccurence);
Subroutine BEGIN: called CC=1 SCAR=0.0
14  
15 sub new {
16 14 ▶ my $class = shift;
Subroutine new: called CC=2 SCAR=7.1
Pod documented
17 14 my %args = @_;
18 bless {
19 _file => $args{file},
20 14 ▶ _mode => $args{mode} // 'all',
Condition50%1/2
$args{"mode"} // "all"
l!l
014
MC/DC0%0/1
$args{"mode"} // "all"
$args{"mode"}
Truth table50%1/2
A
A= $args{"mode"}
Aresult
11
00
21 _hooks => {
22 package => [ qw/package/ ],
23 compile => [ qw/use list prefixedlist if inline moduleload
24 moduleruntime mooselike testrequires tests xxx/ ],
25 runtime => [ qw/require/ ],
26 },
27 _package => {},
28 _compile => {},
29 _runtime => {},
30 }, $class
31 }
32  
33 28 ▶sub file { accessor _file => @_ }
Subroutine file: called CC=1 SCAR=0.0
Pod undocumented
34 210 ▶sub mode { accessor _mode => @_ }
Subroutine mode: called CC=1 SCAR=0.0
Pod undocumented
35  
36 5 ▶sub package { accessor _package => @_ }
Subroutine package: called CC=1 SCAR=0.0
Pod documented
37 453 ▶sub compile { accessor _compile => @_ }
Subroutine compile: called CC=1 SCAR=0.0
Pod documented
38 167 ▶sub runtime { accessor _runtime => @_ }
Subroutine runtime: called CC=1 SCAR=0.0
Pod documented
39 # For pre-0.15 compatibility
40 15 *provides = \&package;
41 15 *requires = \&runtime;
42 15 *uses = \&compile;
43  
44 sub run {
45 14 ▶ my $self = shift;
Subroutine run: called CC=42 SCAR=42.5
Pod documented
46 14 ▶ return 0 unless -r $self->file;
Branch: 1 branch
BranchTrueFalseTotal
unless -r $self->file 0 14 14
47 14 ▶ $self->mode('all')
Branch: 1 branch
BranchTrueFalseTotal
unless $self->mode =~ /^(a(ll)?|p(ackage|rov)?|compile|d(ep)?|r(untime|eq)?|u(se)?)$/ 0 14 14
48 unless $self->mode =~
49 /^(a(ll)?|p(ackage|rov)?|compile|d(ep)?|r(untime|eq)?|u(se)?)$/;
50 14 my $document = PPI::Document->new($self->file, readonly => 1);
51 14 ▶ return 0 unless $document;
Branch: 1 branch
BranchTrueFalseTotal
unless $document 0 14 14
52 14 ▶ my $statements = $document->find('Statement') or return 1;
Branch: 1 branch
BranchTrueFalseTotal
my $statements = $document->find("Statement") or return 1 0 14 14
53 14 my @hooks;
54 14 for my $type (qw(package compile runtime)) {
55 42 for my $hname (@{$self->{_hooks}->{$type}}) {
56 182 my $hook = "Tangerine::hook::$hname";
57 182 ▶ if (eval "require $hook; 1") {
Branch: 1 branch
BranchTrueFalseTotal
if (eval "require $hook; 1") { } 182 0 182
58 182 push @hooks, $hook->new(type => $type);
59 } else {
60 0 warn "Couldn't load the tangerine hook `${hname}'!";
61 }
62 }
63 }
64 @hooks = grep {
65 14 ▶ if ($self->mode =~ /^a/o ||
Branch: 1 branch
BranchTrueFalseTotal
if ($self->mode =~ /^a/o or $_->type eq "package" and $self->mode =~ /^p/o or $_->type eq "compile" and $self->mode =~ /^[cdu]/o or $_->type eq "runtime" and $self->mode =~ /^[dr]/o) 182 0 182
Condition16%3/18
$self->mode =~ /^a/o or $_->type eq "package" and $self->mode =~ /^p/o or $_->type eq "compile" and $self->mode =~ /^[cdu]/o or $_->type eq "runtime" and $self->mode =~ /^[dr]/o
l!l&&r!l&&!r
18200
$self->mode =~ /^a/o or $_->type eq "package" and $self->mode =~ /^p/o or $_->type eq "compile" and $self->mode =~ /^[cdu]/o
l!l&&r!l&&!r
18200
$self->mode =~ /^a/o or $_->type eq "package" and $self->mode =~ /^p/o
l!l&&r!l&&!r
18200
$_->type eq "package" and $self->mode =~ /^p/o
!ll&&!rl&&r
000
$_->type eq "compile" and $self->mode =~ /^[cdu]/o
!ll&&!rl&&r
000
$_->type eq "runtime" and $self->mode =~ /^[dr]/o
!ll&&!rl&&r
000
MC/DC0%0/7
$self->mode =~ /^a/o or $_->type eq "package" and $self->mode =~ /^p/o or $_->type eq "compile" and $self->mode =~ /^[cdu]/o or $_->type eq "runtime" and $self->mode =~ /^[dr]/o
$self->mode =~ /^a/o $_->type eq "package" $self->mode =~ /^p/o $_->type eq "compile" $self->mode =~ /^[cdu]/o $_->type eq "runtime" $self->mode =~ /^[dr]/o
Truth table0%0/16
A or B and C or D and E or F and G
A= $self->mode =~ /^a/oB= $_->type eq "package"C= $self->mode =~ /^p/oD= $_->type eq "compile"E= $self->mode =~ /^[cdu]/oF= $_->type eq "runtime"G= $self->mode =~ /^[dr]/o
ABCDEFGresult
1XXXXXX1
011XXXX1
00X11XX1
01011XX1
00X0X111
00X10111
0100X111
01010111
00X0X0X0
00X0X100
00X100X0
00X10100
0100X0X0
0100X100
010100X0
01010100
66 $_->type eq 'package' && $self->mode =~ /^p/o ||
67 $_->type eq 'compile' && $self->mode =~ /^[cdu]/o ||
68 $_->type eq 'runtime' && $self->mode =~ /^[dr]/o) {
69 182 $_
70 }
71 } @hooks;
72 14 my $children;
73 my $forcetype;
74 14 STATEMENT: for my $statement (@$statements) {
75 151 ▶ $children //= [ $statement->schildren ];
Condition100%2/2
$children //= [$statement->schildren]
l!l
22129
MC/DC100%1/1
$children //= [$statement->schildren]
$children
Truth table100%2/2
A
A= $children
Aresult
11
00
76 151 ▶ if ($children->[1] &&
Branch: 1 branch
BranchTrueFalseTotal
if ($children->[1] and $children->[1] eq "," || $children->[1] eq "=>") 15 136 151
Condition100%6/6
$children->[1] and $children->[1] eq "," || $children->[1] eq "=>"
!ll&&!rl&&r
41407
$children->[1] eq "," or $children->[1] eq "=>"
l!l&&r!l&&!r
87132
MC/DC66%2/3
$children->[1] and $children->[1] eq "," || $children->[1] eq "=>"
$children->[1] $children->[1] eq "," $children->[1] eq "=>"
Truth table75%3/4
A and B or C
A= $children->[1]B= $children->[1] eq ","C= $children->[1] eq "=>"
ABCresult
0XX0
1000
11X1
1011
77 ($children->[1] eq ',' || $children->[1] eq '=>')) {
78 15 undef $children;
79 next STATEMENT
80 15 }
81 136 for my $hook (@hooks) {
82 1811 ▶ if (my $data = $hook->run($children)) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $data = $hook->run($children)) 178 1633 1811
83 178 my $modules = $data->modules;
84 178 ▶ undef %$modules if any { $_ eq '->' } keys %$modules;
Subroutine __ANON__: called CC=1 SCAR=0.2
Branch: 1 branch
BranchTrueFalseTotal
if &any(sub { $_ eq "->"; } , keys %$modules) 0 178 178
85 178 for my $k (keys %$modules) {
86 165 ▶ if ($k !~ m/^[a-z_][a-z0-9_]*(?:::[a-z0-9_]+)*(?:::)?$/io ||
Branch: 1 branch
BranchTrueFalseTotal
if (not $k =~ /^[a-z_][a-z0-9_]*(?:::[a-z0-9_]+)*(?:::)?$/io or $k =~ /^__[A-Z]+__$/o) 8 157 165
Condition66%2/3
not $k =~ /^[a-z_][a-z0-9_]*(?:::[a-z0-9_]+)*(?:::)?$/io or $k =~ /^__[A-Z]+__$/o
l!l&&r!l&&!r
80157
MC/DC50%1/2
not $k =~ /^[a-z_][a-z0-9_]*(?:::[a-z0-9_]+)*(?:::)?$/io or $k =~ /^__[A-Z]+__$/o
not $k =~ /^[a-z_][a-z0-9_]*(?:::[a-z0-9_]+)*(?:::)?$/io $k =~ /^__[A-Z]+__$/o
Truth table66%2/3
not(A) or B
A= not $k =~ /^[a-z_][a-z0-9_]*(?:::[a-z0-9_]+)*(?:::)?$/ioB= $k =~ /^__[A-Z]+__$/o
ABresult
1X1
011
000
87 $k =~ m/^__[A-Z]+__$/o) {
88 8 delete $modules->{$k};
89 next
90 8 }
91 157 ▶ if (my ($class) = ($k =~ /^(.+)::$/o)) {
Branch: 1 branch
BranchTrueFalseTotal
if (my($class) = $k =~ /^(.+)::$/o) 1 156 157
92 $modules->{$class} = $modules->{$k}
93 1 ▶ unless exists $modules->{$class};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $modules->{$class} 1 0 1
94 1 delete $modules->{$k};
95 1 $k = $class
96 }
97 157 $modules->{$k}->line($statement->line_number);
98 }
99 178 ▶ my $type = $forcetype // $hook->type;
Condition66%2/3
$forcetype // $hook->type
l!l&&r!l&&!r
61720
MC/DC0%0/2
$forcetype // $hook->type
$forcetype $hook->type
Truth table66%2/3
A // B
A= $forcetypeB= $hook->type
ABresult
1X1
011
000
100 178 ▶ if ($type eq 'package') {
Branch: 3 branches
BranchTrueFalseTotal
if ($type eq 'package') { } 1 177 178
elsif ($type eq 'compile') { } 128 49 177
elsif ($type eq 'runtime') { } 49 0 49
101 1 $self->package(addoccurence($self->package, $modules));
102 } elsif ($type eq 'compile') {
103 128 $self->compile(addoccurence($self->compile, $modules));
104 } elsif ($type eq 'runtime') {
105 49 $self->runtime(addoccurence($self->runtime, $modules));
106 }
107 178 ▶ if (@{$data->hooks}) {
Branch: 1 branch
BranchTrueFalseTotal
if (@{$data->hooks;}) 14 164 178
108 14 for my $newhook (@{$data->hooks}) {
109 14 ▶ next if ($newhook->type eq 'package') && ($self->mode =~ /^[dcru]/o);
Branch: 1 branch
BranchTrueFalseTotal
if $newhook->type eq "package" and $self->mode =~ /^[dcru]/o 0 14 14
Condition33%1/3
$newhook->type eq "package" and $self->mode =~ /^[dcru]/o
!ll&&!rl&&r
1400
MC/DC0%0/2
$newhook->type eq "package" and $self->mode =~ /^[dcru]/o
$newhook->type eq "package" $self->mode =~ /^[dcru]/o
Truth table33%1/3
A and B
A= $newhook->type eq "package"B= $self->mode =~ /^[dcru]/o
ABresult
0X0
100
111
110 14 ▶ next if ($newhook->type eq 'runtime') && ($self->mode =~ /^[pcu]/o);
Branch: 1 branch
BranchTrueFalseTotal
if $newhook->type eq "runtime" and $self->mode =~ /^[pcu]/o 0 14 14
Condition33%1/3
$newhook->type eq "runtime" and $self->mode =~ /^[pcu]/o
!ll&&!rl&&r
0140
MC/DC0%0/2
$newhook->type eq "runtime" and $self->mode =~ /^[pcu]/o
$newhook->type eq "runtime" $self->mode =~ /^[pcu]/o
Truth table33%1/3
A and B
A= $newhook->type eq "runtime"B= $self->mode =~ /^[pcu]/o
ABresult
0X0
100
111
111 14 ▶ next if ($newhook->type eq 'compile') && ($self->mode =~ /^[pr]/o);
Branch: 1 branch
BranchTrueFalseTotal
if $newhook->type eq "compile" and $self->mode =~ /^[pr]/o 0 14 14
Condition33%1/3
$newhook->type eq "compile" and $self->mode =~ /^[pr]/o
!ll&&!rl&&r
1400
MC/DC0%0/2
$newhook->type eq "compile" and $self->mode =~ /^[pr]/o
$newhook->type eq "compile" $self->mode =~ /^[pr]/o
Truth table33%1/3
A and B
A= $newhook->type eq "compile"B= $self->mode =~ /^[pr]/o
ABresult
0X0
100
111
112 push @hooks, $newhook
113 if none {
114 191 ▶ blessed($newhook) eq blessed($_) &&
Subroutine __ANON__: called CC=2 SCAR=6.9
Branch: 1 branch
BranchTrueFalseTotal
builtin::blessed($newhook) eq builtin::blessed($_) and $newhook->type eq $_->type 19 172 191
115 $newhook->type eq $_->type
116 14 ▶ } @hooks;
Branch: 1 branch
BranchTrueFalseTotal
if &none(sub { builtin::blessed($newhook) eq builtin::blessed($_) and $newhook->type eq $_->type; } , @hooks) 8 6 14
117 }
118 }
119 178 ▶ if (@{$data->children}) {
Branch: 1 branch
BranchTrueFalseTotal
if (@{$data->children;}) 22 156 178
120 22 $children = $data->children;
121 22 $forcetype = $data->type;
122 22 redo STATEMENT;
123 }
124 }
125 }
126 114 undef $children,
127 undef $forcetype;
128 }
129 14 1;
130 }
131  
132 15 1;
133  
134 __END__
↑ Summary Tangerine/hook/if.pm »