PackageIndexer/PPI/Inheritance.pm

filter: Statementstmt 95.0% 76 / 80 Branchbran 68.7% 33 / 48 Conditioncond 54.5% 18 / 33 MC/DCmcdc 31.5% 6 / 19 Subroutinesub 100% 7 / 7 Podpod 0.0% 0 / 2 totaltotal 74.0% 140 / 189 CC 36 SCAR 23.6
CC
36
Cov
79%
handle_isa
13.6
_handle_assign
11.4
_handle_extend
10.6
CRAP 10.6
« PackageIndexer.pm ↑ Summary
1 package File::PackageIndexer::PPI::Inheritance;
2  
3 9 ▶use 5.008001;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 9 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 9 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 9 our $VERSION = '0.01';
8  
9  
10 # The base case
11 44 ▶sub handle_base {
Subroutine handle_base: called CC=7 SCAR=21.0
Pod undocumented
12 44 my $indexer = shift;
13 44 my $statement = shift;
14 44 my $curpkg = shift;
15 44 my $pkgs = shift;
16 44 ▶ if (not defined $curpkg) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $curpkg) 0 44 44
17 0 $curpkg = $indexer->lazy_create_pkg($indexer->default_package, $pkgs);
18 }
19  
20 44 my $list_start = $statement->schild(0)->snext_sibling;
21 44 my $classes = File::PackageIndexer::PPI::Util::list_structure_to_array($list_start);
22  
23 return
24 44 ▶ if not defined $classes or ref($classes) ne 'ARRAY';
Branch: 1 branch
BranchTrueFalseTotal
if not defined $classes or ref $classes ne "ARRAY" 0 44 44
Condition33%1/3
not defined $classes or ref $classes ne "ARRAY"
l!l&&r!l&&!r
0044
MC/DC0%0/2
not defined $classes or ref $classes ne "ARRAY"
not defined $classes ref $classes ne "ARRAY"
Truth table33%1/3
not(A) or B
A= not defined $classesB= ref $classes ne "ARRAY"
ABresult
1X1
011
000
25  
26 # remove options if 'parent'
27 44 ▶ if ($list_start->content() eq 'parent') {
Branch: 1 branch
BranchTrueFalseTotal
if ($list_start->content eq "parent") 18 26 44
28 18 @$classes = grep $_ !~ /^-/, @$classes;
29 }
30  
31 44 ▶ push @{$curpkg->{begin_isa}}, @$classes
Branch: 1 branch
BranchTrueFalseTotal
if defined $classes and ref $classes eq "ARRAY" 44 0 44
Condition33%1/3
defined $classes and ref $classes eq "ARRAY"
!ll&&!rl&&r
0044
MC/DC0%0/2
defined $classes and ref $classes eq "ARRAY"
defined $classes ref $classes eq "ARRAY"
Truth table33%1/3
A and B
A= defined $classesB= ref $classes eq "ARRAY"
ABresult
0X0
100
111
32 if defined $classes and ref($classes) eq 'ARRAY';
33  
34 44 return 1;
35 }
36  
37 # assumes that the statement contains @ISA somehow!
38 85 ▶sub handle_isa {
Subroutine handle_isa: called CC=12 SCAR=26.1
Pod undocumented
39 85 my $indexer = shift;
40 85 my $statement = shift;
41 85 my $curpkg = shift;
42 85 my $pkgs = shift;
43 85 my $in_scheduled_block = shift;
44  
45 # skip if @ISA is modified in END block.
46 return
47 85 ▶ if defined $in_scheduled_block and $in_scheduled_block eq 'END';
Branch: 1 branch
BranchTrueFalseTotal
if defined $in_scheduled_block and $in_scheduled_block eq "END" 3 82 85
Condition66%2/3
defined $in_scheduled_block and $in_scheduled_block eq "END"
!ll&&!rl&&r
0823
MC/DC50%1/2
defined $in_scheduled_block and $in_scheduled_block eq "END"
defined $in_scheduled_block $in_scheduled_block eq "END"
Truth table66%2/3
A and B
A= defined $in_scheduled_blockB= $in_scheduled_block eq "END"
ABresult
0X0
100
111
48  
49 return
50 82 ▶ unless $statement->isa("PPI::Statement");
Branch: 1 branch
BranchTrueFalseTotal
unless $statement->isa("PPI::Statement") 0 82 82
51  
52 82 my $child = $statement->schild(0);
53 82 ▶ return if not $child;
Branch: 1 branch
BranchTrueFalseTotal
unless $child 0 82 82
54  
55 # push/unshift @ISA...
56 82 ▶ if ($child->isa("PPI::Token::Word") and $child->content =~ /^(?:unshift|push)$/) {
Branch: 3 branches
BranchTrueFalseTotal
if ($child->isa('PPI::Token::Word') and $child->content =~ /^(?:unshift|push)$/) { } 45 37 82
elsif ($statement->isa('PPI::Statement::Variable')) { } 21 16 37
elsif ($statement->content =~ /\@ISA\s*\)?\s*=/) { } 16 0 16
Condition100%3/3
$child->isa("PPI::Token::Word") and $child->content =~ /^(?:unshift|push)$/
!ll&&!rl&&r
162145
MC/DC100%2/2
$child->isa("PPI::Token::Word") and $child->content =~ /^(?:unshift|push)$/
$child->isa("PPI::Token::Word") $child->content =~ /^(?:unshift|push)$/
Truth table100%3/3
A and B
A= $child->isa("PPI::Token::Word")B= $child->content =~ /^(?:unshift|push)$/
ABresult
0X0
100
111
57 45 _handle_extend($indexer, $statement, $curpkg, $pkgs, $in_scheduled_block);
58 }
59 # our @ISA ...
60 elsif ( $statement->isa("PPI::Statement::Variable") ) {
61 21 ▶ if ( $statement->type eq 'our'
Branch: 1 branch
BranchTrueFalseTotal
if ($statement->type eq "our" and $statement->variables and ($statement->variables)[0] eq "\@ISA") 21 0 21
Condition33%2/6
$statement->type eq "our" and $statement->variables and ($statement->variables)[0] eq "\@ISA"
!ll&&!rl&&r
0021
$statement->type eq "our" and $statement->variables
!ll&&!rl&&r
0021
MC/DC0%0/3
$statement->type eq "our" and $statement->variables and ($statement->variables)[0] eq "\@ISA"
$statement->type eq "our" $statement->variables ($statement->variables)[0] eq "\@ISA"
Truth table25%1/4
A and B and C
A= $statement->type eq "our"B= $statement->variablesC= ($statement->variables)[0] eq "\@ISA"
ABCresult
0XX0
10X0
1100
1111
62 and $statement->variables
63 and ($statement->variables)[0] eq '@ISA' )
64 {
65 # declare and assign can probably be handled by the same code
66 21 _handle_assign($indexer, $statement, $curpkg, $pkgs, $in_scheduled_block);
67 }
68 # else: do nothing. my/local shouldn't be used for @ISA!
69 }
70 # @ISA = ...
71 # could this be done more elegantly?
72 elsif (
73 $statement->content =~ /\@ISA\s*\)?\s*=/
74 ) {
75 16 _handle_assign($indexer, $statement, $curpkg, $pkgs, $in_scheduled_block);
76 }
77
78 }
79  
80  
81 45 ▶sub _handle_extend {
Subroutine _handle_extend: called CC=9 SCAR=23.6
82 45 my $indexer = shift;
83 45 my $statement = shift;
84 45 my $curpkg = shift;
85 45 my $pkgs = shift;
86 45 my $in_scheduled_block = shift;
87  
88 45 ▶ if (not defined $curpkg) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $curpkg) 0 45 45
89 0 $curpkg = $indexer->lazy_create_pkg($indexer->default_package, $pkgs);
90 }
91  
92 45 my $child = $statement->schild(0);
93 45 my $type = $child->content;
94  
95 # $child = $child->snext_sibling;
96 # return unless defined $child;
97 45 my $arguments = File::PackageIndexer::PPI::Util::list_structure_to_array($child);
98 return
99 45 ▶ unless defined $arguments
Branch: 1 branch
BranchTrueFalseTotal
unless defined $arguments and @$arguments and $arguments->[0] eq "\@ISA" 0 45 45
Condition33%2/6
defined $arguments and @$arguments and $arguments->[0] eq "\@ISA"
!ll&&!rl&&r
0045
defined $arguments and @$arguments
!ll&&!rl&&r
0045
MC/DC0%0/3
defined $arguments and @$arguments and $arguments->[0] eq "\@ISA"
defined $arguments @$arguments $arguments->[0] eq "\@ISA"
Truth table25%1/4
A and B and C
A= defined $argumentsB= @$argumentsC= $arguments->[0] eq "\@ISA"
ABCresult
0XX0
10X0
1100
1111
100 and @$arguments
101 and $arguments->[0] eq '@ISA';
102 45 shift @$arguments;
103  
104 45 ▶ if ($type eq 'push') {
Branch: 2 branches
BranchTrueFalseTotal
if ($type eq 'push') { } 26 19 45
elsif ($type eq 'unshift') { } 19 0 19
105 26 ▶ push @{ $in_scheduled_block eq 'BEGIN' ? $curpkg->{begin_isa} : $curpkg->{isa_push} }, @$arguments;
Branch: 1 branch
BranchTrueFalseTotal
$in_scheduled_block eq 'BEGIN' ? : 3 23 26
106 }
107 elsif ($type eq 'unshift') {
108 19 ▶ unshift @{ $in_scheduled_block eq 'BEGIN' ? $curpkg->{begin_isa} : $curpkg->{isa_unshift} }, @$arguments;
Branch: 1 branch
BranchTrueFalseTotal
$in_scheduled_block eq 'BEGIN' ? : 0 19 19
109 }
110 else {
111 0 die "Unknown operation on \@ISA: '$type'";
112 }
113  
114 45 return();
115 }
116  
117  
118 # either "our @ISA" or "@ISA ="
119 37 ▶sub _handle_assign {
Subroutine _handle_assign: called CC=11 SCAR=24.4
120 37 my $indexer = shift;
121 37 my $statement = shift;
122 37 my $curpkg = shift;
123 37 my $pkgs = shift;
124 37 my $in_scheduled_block = shift;
125  
126 37 ▶ if (not defined $curpkg) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $curpkg) 0 37 37
127 0 $curpkg = $indexer->lazy_create_pkg($indexer->default_package, $pkgs);
128 }
129  
130 37 my $child = $statement->schild(0);
131 37 ▶ return unless $child;
Branch: 1 branch
BranchTrueFalseTotal
unless $child 0 37 37
132
133 # skip until =
134 37 ▶ $child = $child->snext_sibling()
Branch: 1 branch
BranchTrueFalseTotal
$child and not $child->isa("PPI::Token::Operator") and not $child->content eq "=" and do { $child = $child->snext_sibling } 76 37 113
Condition83%5/6
$child and not $child->isa("PPI::Token::Operator") and not $child->content eq "="
!ll&&!rl&&r
37076
$child and not $child->isa("PPI::Token::Operator")
!ll&&!rl&&r
181976
MC/DC66%2/3
$child and not $child->isa("PPI::Token::Operator") and not $child->content eq "="
$child not $child->isa("PPI::Token::Operator") not $child->content eq "="
Truth table75%3/4
A and not(B) and not(C)
A= $childB= not $child->isa("PPI::Token::Operator")C= not $child->content eq "="
ABCresult
0XX0
10X0
1100
1111
135 while $child
136 and not $child->isa("PPI::Token::Operator")
137 and not $child->content eq '=';
138 37 ▶ return unless $child;
Branch: 1 branch
BranchTrueFalseTotal
unless $child 18 19 37
139  
140 19 my $arguments = File::PackageIndexer::PPI::Util::list_structure_to_array($child);
141  
142 return
143 19 ▶ unless defined $arguments;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $arguments 0 19 19
144  
145 19 ▶ if ($in_scheduled_block and $in_scheduled_block ne 'END') {
Branch: 2 branches
BranchTrueFalseTotal
if ($in_scheduled_block and $in_scheduled_block ne 'END') { } 8 11 19
elsif (not $in_scheduled_block) { } 11 0 11
Condition66%2/3
$in_scheduled_block and $in_scheduled_block ne "END"
!ll&&!rl&&r
1108
MC/DC50%1/2
$in_scheduled_block and $in_scheduled_block ne "END"
$in_scheduled_block $in_scheduled_block ne "END"
Truth table66%2/3
A and B
A= $in_scheduled_blockB= $in_scheduled_block ne "END"
ABresult
0X0
100
111
146 8 @{ $curpkg->{begin_isa} } = @$arguments;
147 8 $curpkg->{isa_cleared_at_compiletime} = 1;
148 }
149 elsif(!$in_scheduled_block) {
150 11 @{ $curpkg->{isa_push} } = @$arguments;
151 11 @{ $curpkg->{isa_unshift} } = ();
152 11 $curpkg->{isa_cleared_at_runtime} = 1;
153 }
154 else {
155 # END, skip
156 }
157  
158 19 return();
159 }
160  
161 9 1;
162  
163 __END__
« PackageIndexer.pm ↑ Summary