| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 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
Condition33%1/3
not defined $classes or ref $classes ne "ARRAY"
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"
| |||||||||||||||||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||||||||||||||||
| 26 | # remove options if 'parent' | ||||||||||||||||||||||||||||||||||||||||||
| 27 | 44 | ▶ | if ($list_start->content() eq 'parent') { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 28 | 18 | @$classes = grep $_ !~ /^-/, @$classes; | |||||||||||||||||||||||||||||||||||||||||
| 29 | } | ||||||||||||||||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||||||||||||||||
| 31 | 44 | ▶ | push @{$curpkg->{begin_isa}}, @$classes | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $classes and ref $classes eq "ARRAY"
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"
| |||||||||||||||||||||||||||||||||||||||||||
| 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
Condition66%2/3
defined $in_scheduled_block and $in_scheduled_block eq "END"
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"
| |||||||||||||||||||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||||||||||||||||
| 49 | return | ||||||||||||||||||||||||||||||||||||||||||
| 50 | 82 | ▶ | unless $statement->isa("PPI::Statement"); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||||||||||||||||
| 52 | 82 | my $child = $statement->schild(0); | |||||||||||||||||||||||||||||||||||||||||
| 53 | 82 | ▶ | return if not $child; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||||||||||||||||
| 55 | # push/unshift @ISA... | ||||||||||||||||||||||||||||||||||||||||||
| 56 | 82 | ▶ | if ($child->isa("PPI::Token::Word") and $child->content =~ /^(?:unshift|push)$/) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
Condition100%3/3
$child->isa("PPI::Token::Word") and $child->content =~ /^(?:unshift|push)$/
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)$/
| |||||||||||||||||||||||||||||||||||||||||||
| 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
Condition33%2/6
$statement->type eq "our" and $statement->variables and ($statement->variables)[0] eq "\@ISA"
$statement->type eq "our" and $statement->variables
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"
| |||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 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
Condition33%2/6
defined $arguments and @$arguments and $arguments->[0] eq "\@ISA"
defined $arguments and @$arguments
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"
| |||||||||||||||||||||||||||||||||||||||||||
| 100 | and @$arguments | ||||||||||||||||||||||||||||||||||||||||||
| 101 | and $arguments->[0] eq '@ISA'; | ||||||||||||||||||||||||||||||||||||||||||
| 102 | 45 | shift @$arguments; | |||||||||||||||||||||||||||||||||||||||||
| 103 | |||||||||||||||||||||||||||||||||||||||||||
| 104 | 45 | ▶ | if ($type eq 'push') { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 105 | 26 | ▶ | push @{ $in_scheduled_block eq 'BEGIN' ? $curpkg->{begin_isa} : $curpkg->{isa_push} }, @$arguments; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 106 | } | ||||||||||||||||||||||||||||||||||||||||||
| 107 | elsif ($type eq 'unshift') { | ||||||||||||||||||||||||||||||||||||||||||
| 108 | 19 | ▶ | unshift @{ $in_scheduled_block eq 'BEGIN' ? $curpkg->{begin_isa} : $curpkg->{isa_unshift} }, @$arguments; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 132 | |||||||||||||||||||||||||||||||||||||||||||
| 133 | # skip until = | ||||||||||||||||||||||||||||||||||||||||||
| 134 | 37 | ▶ | $child = $child->snext_sibling() | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition83%5/6
$child and not $child->isa("PPI::Token::Operator") and not $child->content eq "="
$child and not $child->isa("PPI::Token::Operator")
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 "="
| |||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 144 | |||||||||||||||||||||||||||||||||||||||||||
| 145 | 19 | ▶ | if ($in_scheduled_block and $in_scheduled_block ne 'END') { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition66%2/3
$in_scheduled_block and $in_scheduled_block ne "END"
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"
| |||||||||||||||||||||||||||||||||||||||||||
| 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__ | ||||||||||||||||||||||||||||||||||||||||||