Tangerine.pm

filter: Statementstmt 98.9% 96 / 97 Branchbran 72.7% 32 / 44 Conditioncond 44.1% 19 / 43 MC/DCmcdc 22.7% 5 / 22 Subroutinesub 100% 18 / 18 Podpod 71.4% 5 / 7 totaltotal 75.7% 175 / 231 CC 44 SCAR 38.9
CC
44
Cov
80%
run
70.1
new
2.0
__ANON__
2.0
CRAP 48.7
↑ Summary Tangerine/hook/if.pm »
1 package Tangerine;
2 16 $Tangerine::VERSION = '0.23';
3 # ABSTRACT: Examine perl files and report dependency metadata
4 16 ▶use 5.010;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 16 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 16 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 16 ▶use utf8;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 16 ▶use PPI;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 16 ▶use Scalar::Util qw(blessed);
Subroutine BEGIN: called CC=1 SCAR=0.0
10 16 ▶use Tangerine::Hook;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 16 ▶use Tangerine::Occurence;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 16 ▶use Tangerine::Utils qw(any accessor addoccurence none);
Subroutine BEGIN: called CC=1 SCAR=0.0
13  
14 15 ▶sub new {
Subroutine new: called CC=2 SCAR=7.1
Pod documented
15 15 my $class = shift;
16 15 my %args = @_;
17 bless {
18 _file => $args{file},
19 15 ▶ _mode => $args{mode} // 'all',
Condition50%1/2
$args{"mode"} // "all"
l!l
015
MC/DC0%0/1
$args{"mode"} // "all"
$args{"mode"}
Truth table50%1/2
A
A= $args{"mode"}
Aresult
11
00
20 _hooks => {
21 package => [ qw/package/ ],
22 compile => [ qw/use list prefixedlist if inline moduleload
23 moduleruntime mooselike testrequires tests xxx/ ],
24 runtime => [ qw/require/ ],
25 },
26 _package => {},
27 _compile => {},
28 _runtime => {},
29 }, $class
30 }
31  
32 30 ▶sub file { accessor _file => @_ }
Subroutine file: called CC=1 SCAR=0.0
Pod undocumented
33 227 ▶sub mode { accessor _mode => @_ }
Subroutine mode: called CC=1 SCAR=0.0
Pod undocumented
34  
35 5 ▶sub package { accessor _package => @_ }
Subroutine package: called CC=1 SCAR=0.0
Pod documented
36 488 ▶sub compile { accessor _compile => @_ }
Subroutine compile: called CC=1 SCAR=0.0
Pod documented
37 177 ▶sub runtime { accessor _runtime => @_ }
Subroutine runtime: called CC=1 SCAR=0.0
Pod documented
38 # For pre-0.15 compatibility
39 16 *provides = \&package;
40 16 *requires = \&runtime;
41 16 *uses = \&compile;
42  
43 15 ▶sub run {
Subroutine run: called CC=42 SCAR=42.5
Pod documented
44 15 my $self = shift;
45 15 ▶ return 0 unless -r $self->file;
Branch: 1 branch
BranchTrueFalseTotal
unless -r $self->file 0 15 15
46 15 ▶ $self->mode('all')
Branch: 1 branch
BranchTrueFalseTotal
unless $self->mode =~ /^(a(ll)?|p(ackage|rov)?|compile|d(ep)?|r(untime|eq)?|u(se)?)$/ 0 15 15
47 unless $self->mode =~
48 /^(a(ll)?|p(ackage|rov)?|compile|d(ep)?|r(untime|eq)?|u(se)?)$/;
49 15 my $document = PPI::Document->new($self->file, readonly => 1);
50 15 ▶ return 0 unless $document;
Branch: 1 branch
BranchTrueFalseTotal
unless $document 0 15 15
51 15 ▶ my $statements = $document->find('Statement') or return 1;
Branch: 1 branch
BranchTrueFalseTotal
my $statements = $document->find("Statement") or return 1 15 0 15
52 15 my @hooks;
53 15 for my $type (qw(package compile runtime)) {
54 45 for my $hname (@{$self->{_hooks}->{$type}}) {
55 195 my $hook = "Tangerine::hook::$hname";
56 195 ▶ if (eval "require $hook; 1") {
Branch: 1 branch
BranchTrueFalseTotal
if (eval "require $hook; 1") { } 195 0 195
57 195 push @hooks, $hook->new(type => $type);
58 } else {
59 0 warn "Couldn't load the tangerine hook `${hname}'!";
60 }
61 }
62 }
63 @hooks = grep {
64 15 ▶ 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) 195 0 195
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
19500
$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
19500
$self->mode =~ /^a/o or $_->type eq "package" and $self->mode =~ /^p/o
l!l&&r!l&&!r
19500
$_->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 table6%1/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
65 $_->type eq 'package' && $self->mode =~ /^p/o ||
66 $_->type eq 'compile' && $self->mode =~ /^[cdu]/o ||
67 $_->type eq 'runtime' && $self->mode =~ /^[dr]/o) {
68 195 $_
69 }
70 } @hooks;
71 15 my $children;
72 my $forcetype;
73 15 STATEMENT: for my $statement (@$statements) {
74 159 ▶ $children //= [ $statement->schildren ];
Condition100%2/2
$children //= [$statement->schildren]
l!l
22137
MC/DC100%1/1
$children //= [$statement->schildren]
$children
Truth table100%2/2
A
A= $children
Aresult
11
00
75 159 ▶ if ($children->[1] &&
Branch: 1 branch
BranchTrueFalseTotal
if ($children->[1] and $children->[1] eq "," || $children->[1] eq "=>") 17 142 159
Condition100%6/6
$children->[1] and $children->[1] eq "," || $children->[1] eq "=>"
!ll&&!rl&&r
413817
$children->[1] eq "," or $children->[1] eq "=>"
l!l&&r!l&&!r
98138
MC/DC100%3/3
$children->[1] and $children->[1] eq "," || $children->[1] eq "=>"
$children->[1] $children->[1] eq "," $children->[1] eq "=>"
Truth table100%4/4
A and B or C
A= $children->[1]B= $children->[1] eq ","C= $children->[1] eq "=>"
ABCresult
0XX0
1000
11X1
1011
76 ($children->[1] eq ',' || $children->[1] eq '=>')) {
77 17 undef $children;
78 next STATEMENT
79 17 }
80 142 for my $hook (@hooks) {
81 1894 ▶ if (my $data = $hook->run($children)) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $data = $hook->run($children)) 190 1704 1894
82 190 my $modules = $data->modules;
83 190 ▶ 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 190 190
84 190 for my $k (keys %$modules) {
85 176 ▶ 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 168 176
Condition66%2/3
not $k =~ /^[a-z_][a-z0-9_]*(?:::[a-z0-9_]+)*(?:::)?$/io or $k =~ /^__[A-Z]+__$/o
l!l&&r!l&&!r
80168
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
86 $k =~ m/^__[A-Z]+__$/o) {
87 8 delete $modules->{$k};
88 next
89 8 }
90 168 ▶ if (my ($class) = ($k =~ /^(.+)::$/o)) {
Branch: 1 branch
BranchTrueFalseTotal
if (my($class) = $k =~ /^(.+)::$/o) 1 167 168
91 $modules->{$class} = $modules->{$k}
92 1 ▶ unless exists $modules->{$class};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $modules->{$class} 1 0 1
93 1 delete $modules->{$k};
94 1 $k = $class
95 }
96 168 $modules->{$k}->line($statement->line_number);
97 }
98 190 ▶ my $type = $forcetype // $hook->type;
Condition66%2/3
$forcetype // $hook->type
l!l&&r!l&&!r
61840
MC/DC0%0/2
$forcetype // $hook->type
$forcetype $hook->type
Truth table66%2/3
A // B
A= $forcetypeB= $hook->type
ABresult
1X1
011
000
99 190 ▶ if ($type eq 'package') {
Branch: 3 branches
BranchTrueFalseTotal
if ($type eq 'package') { } 1 189 190
elsif ($type eq 'compile') { } 138 51 189
elsif ($type eq 'runtime') { } 51 0 51
100 1 $self->package(addoccurence($self->package, $modules));
101 } elsif ($type eq 'compile') {
102 138 $self->compile(addoccurence($self->compile, $modules));
103 } elsif ($type eq 'runtime') {
104 51 $self->runtime(addoccurence($self->runtime, $modules));
105 }
106 190 ▶ if (@{$data->hooks}) {
Branch: 1 branch
BranchTrueFalseTotal
if (@{$data->hooks;}) 17 173 190
107 17 for my $newhook (@{$data->hooks}) {
108 17 ▶ 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 17 17
Condition33%1/3
$newhook->type eq "package" and $self->mode =~ /^[dcru]/o
!ll&&!rl&&r
1700
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
109 17 ▶ 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 17 17
Condition33%1/3
$newhook->type eq "runtime" and $self->mode =~ /^[pcu]/o
!ll&&!rl&&r
0170
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
110 17 ▶ 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 17 17
Condition33%1/3
$newhook->type eq "compile" and $self->mode =~ /^[pr]/o
!ll&&!rl&&r
1700
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
111 push @hooks, $newhook
112 232 ▶ if none {
Subroutine __ANON__: called CC=2 SCAR=6.9
113 232 ▶ blessed($newhook) eq blessed($_) &&
Branch: 1 branch
BranchTrueFalseTotal
builtin::blessed($newhook) eq builtin::blessed($_) and $newhook->type eq $_->type 24 208 232
114 $newhook->type eq $_->type
115 17 ▶ } @hooks;
Branch: 1 branch
BranchTrueFalseTotal
if &none(sub { builtin::blessed($newhook) eq builtin::blessed($_) and $newhook->type eq $_->type; } , @hooks) 9 8 17
116 }
117 }
118 190 ▶ if (@{$data->children}) {
Branch: 1 branch
BranchTrueFalseTotal
if (@{$data->children;}) 22 168 190
119 22 $children = $data->children;
120 22 $forcetype = $data->type;
121 22 redo STATEMENT;
122 }
123 }
124 }
125 120 undef $children,
126 undef $forcetype;
127 }
128 15 1;
129 }
130  
131 16 1;
132  
133 __END__
↑ Summary Tangerine/hook/if.pm »