| 1 | package File::PackageIndexer::PPI::Util; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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 | # try to regenerate a hash or array struct from | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 10 | # a PPI::Structure::Constructor (anon hash/array constr.) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 11 | 51 | ▶ | sub constructor_to_structure { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
constructor_to_structure: called CC=5 SCAR=16.8
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 12 | 51 | my $token = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 14 | 51 | ▶ | return() unless $token->isa("PPI::Structure::Constructor"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 16 | 51 | my $start = $token->start; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 17 | 51 | ▶ | return() unless $start->isa("PPI::Token::Structure"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 18 | 51 | ▶ | if ($start->content eq '{') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 19 | 34 | return _hash_constructor_to_structure($token); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 20 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 21 | elsif ($start->content eq '[') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 22 | 17 | return _array_constructor_to_structure($token); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 23 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 24 | 0 | return(); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 25 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 27 | 0 | ▶ | sub list_structure_to_hash { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
list_structure_to_hash: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 28 | 0 | my $token = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 30 | #return() unless $token->isa("PPI::Structure::List"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 32 | 0 | return _hash_constructor_to_structure($token); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 33 | 0 | return(); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 34 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 36 | 117 | ▶ | sub list_structure_to_array { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
list_structure_to_array: called CC=1 SCAR=0.4
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 37 | 117 | my $token = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 39 | #return() unless $token->isa("PPI::Structure::List"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 41 | 117 | return _array_constructor_to_structure($token); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 42 | 0 | return(); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 43 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 45 | 34 | ▶ | sub _hash_constructor_to_structure { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_hash_constructor_to_structure: called CC=28 SCAR=35.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 46 | 34 | my $hash = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 48 | 34 | my $struct = {}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 50 | 34 | my $state = 'key'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 51 | 34 | my $key; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 53 | # either use the children or walk the siblings | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 54 | 34 | ▶ | my $use_siblings = $hash->can('schildren') ? 0 : 1; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 55 | 34 | ▶ | my @children = $use_siblings ? () : $hash->schildren(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 56 | 34 | ▶ | my $token = $use_siblings ? $hash : undef; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 57 | 34 | while (1) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 58 | 242 | ▶ | if (@children) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 59 | 208 | $token = shift @children; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 60 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 61 | elsif ($use_siblings) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 62 | 0 | $token = $token->snext_sibling(); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 63 | 0 | ▶ | last if not defined $token or not ref($token); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
defined $token and ref $token
MC/DC0%0/2
defined $token and ref $token
defined $token
ref $token
Truth table0%0/3
A and B
A= defined $tokenB= ref $token
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 64 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 65 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 66 | 34 | last; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 67 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 69 | # flatten | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 70 | 208 | ▶ | if ($token->isa("PPI::Statement") or $token->isa("PPI::Structure::List")) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$token->isa("PPI::Statement") or $token->isa("PPI::Structure::List")
MC/DC50%1/2
$token->isa("PPI::Statement") or $token->isa("PPI::Structure::List")
$token->isa("PPI::Statement")
$token->isa("PPI::Structure::List")
Truth table66%2/3
A or B
A= $token->isa("PPI::Statement")B= $token->isa("PPI::Structure::List")
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 71 | 34 | my @ch = $token->schildren(); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 73 | # pop trailing commas | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 74 | 34 | ▶ | while (@ch and $ch[-1]->isa("PPI::Token::Operator") || $ch[-1]->content =~ /^(?:,|=>)$/) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%4/6
@ch and $ch[-1]->isa("PPI::Token::Operator") || $ch[-1]->content =~ /^(?:,|=>)$/
$ch[-1]->isa("PPI::Token::Operator") or $ch[-1]->content =~ /^(?:,|=>)$/
MC/DC33%1/3
@ch and $ch[-1]->isa("PPI::Token::Operator") || $ch[-1]->content =~ /^(?:,|=>)$/
@ch
$ch[-1]->isa("PPI::Token::Operator")
$ch[-1]->content =~ /^(?:,|=>)$/
Truth table50%2/4
A and B or C
A= @chB= $ch[-1]->isa("PPI::Token::Operator")C= $ch[-1]->content =~ /^(?:,|=>)$/
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 75 | 3 | pop(@ch); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 76 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 77 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 78 | 34 | unshift @children, @ch; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 79 | 34 | next; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 80 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 81 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 82 | # semicolon | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 83 | 174 | ▶ | return($struct) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$token->isa("PPI::Token::Structure") and $token->content eq ";"
MC/DC0%0/2
$token->isa("PPI::Token::Structure") and $token->content eq ";"
$token->isa("PPI::Token::Structure")
$token->content eq ";"
Truth table33%1/3
A and B
A= $token->isa("PPI::Token::Structure")B= $token->content eq ";"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 84 | if $token->isa("PPI::Token::Structure") | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 85 | and $token->content eq ';'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 87 | # special case: qw() | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 88 | 174 | ▶ | if ( ($state eq 'key' or $state eq 'value') | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%6/6
$state eq "key" || $state eq "value" and $token->isa("PPI::Token::QuoteLike::Words")
$state eq "key" or $state eq "value"
MC/DC100%3/3
$state eq "key" || $state eq "value" and $token->isa("PPI::Token::QuoteLike::Words")
$state eq "key"
$state eq "value"
$token->isa("PPI::Token::QuoteLike::Words")
Truth table100%5/5
A or B and C
A= $state eq "key"B= $state eq "value"C= $token->isa("PPI::Token::QuoteLike::Words")
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 89 | and $token->isa("PPI::Token::QuoteLike::Words") ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 90 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 91 | 4 | my @values = qw_to_list($token); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 92 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 93 | # emulate the state flip flop to end up in a consistent state afterwards | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 94 | 4 | foreach my $v (@values) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 95 | 8 | ▶ | if ($state eq 'key') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 96 | 4 | $key = $v; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 97 | 4 | $state = 'value'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 98 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 99 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 100 | 4 | $struct->{$key} = $v; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 101 | 4 | $key = undef; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 102 | 4 | $state = 'key'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 103 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 104 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 105 | 4 | $state = 'comma'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 106 | 4 | next; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 107 | } # end special case 'qw' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 108 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 109 | 170 | ▶ | if ($state eq 'key') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 110 | 50 | my $keyname = get_keyname($token); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 111 | 50 | ▶ | return() if not defined $keyname; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 112 | 50 | $key = $keyname; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 113 | 50 | $state = 'comma'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 114 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 115 | elsif ($state eq 'comma') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 116 | 70 | ▶ | return() unless $token->isa("PPI::Token::Operator"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 117 | 70 | ▶ | return() unless $token->content =~ /^(?:,|=>)$/; # are there other valid comma-likes? | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 118 | 70 | ▶ | $state = defined($key) ? 'value' : 'key'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 119 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 120 | elsif ($state eq 'value') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 121 | 50 | my $value = token_to_string($token); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 122 | 50 | ▶ | return() unless defined $value; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 123 | 50 | $struct->{$key} = $value; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 124 | 50 | $key = undef; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 125 | 50 | $state = 'comma'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 126 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 127 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 128 | 0 | die "Sanity check: Unknown state!"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 129 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 130 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 131 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 132 | 34 | return($struct); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 133 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 134 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 135 | 134 | ▶ | sub _array_constructor_to_structure { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_array_constructor_to_structure: called CC=21 SCAR=30.7
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 136 | 134 | my $array = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 137 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 138 | 134 | my $struct = []; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 139 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 140 | 134 | my $state = 'elem'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 141 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 142 | # either use the children or walk the siblings | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 143 | 134 | ▶ | my $use_siblings = $array->can('schildren') ? 0 : 1; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 144 | 134 | ▶ | my @children = $use_siblings ? () : $array->schildren(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 145 | 134 | ▶ | my $token = $use_siblings ? $array : undef; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 146 | 134 | while (1) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 147 | 546 | ▶ | if (@children) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 148 | 200 | $token = shift @children; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 149 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 150 | elsif ($use_siblings) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 151 | 320 | $token = $token->snext_sibling(); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 152 | 320 | ▶ | last if not defined $token or not ref($token); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
defined $token and ref $token
MC/DC50%1/2
defined $token and ref $token
defined $token
ref $token
Truth table66%2/3
A and B
A= defined $tokenB= ref $token
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 153 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 154 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 155 | 26 | last; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 156 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 157 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 158 | # flatten | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 159 | 490 | ▶ | if ($token->isa("PPI::Statement") or $token->isa("PPI::Structure::List")) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$token->isa("PPI::Statement") or $token->isa("PPI::Structure::List")
MC/DC100%2/2
$token->isa("PPI::Statement") or $token->isa("PPI::Structure::List")
$token->isa("PPI::Statement")
$token->isa("PPI::Structure::List")
Truth table100%3/3
A or B
A= $token->isa("PPI::Statement")B= $token->isa("PPI::Structure::List")
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 160 | 101 | my @ch = $token->schildren(); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 161 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 162 | # pop trailing commas | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 163 | 101 | ▶ | while (@ch and $ch[-1]->isa("PPI::Token::Operator") || $ch[-1]->content =~ /^(?:,|=>)$/) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition83%5/6
@ch and $ch[-1]->isa("PPI::Token::Operator") || $ch[-1]->content =~ /^(?:,|=>)$/
$ch[-1]->isa("PPI::Token::Operator") or $ch[-1]->content =~ /^(?:,|=>)$/
MC/DC66%2/3
@ch and $ch[-1]->isa("PPI::Token::Operator") || $ch[-1]->content =~ /^(?:,|=>)$/
@ch
$ch[-1]->isa("PPI::Token::Operator")
$ch[-1]->content =~ /^(?:,|=>)$/
Truth table75%3/4
A and B or C
A= @chB= $ch[-1]->isa("PPI::Token::Operator")C= $ch[-1]->content =~ /^(?:,|=>)$/
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 164 | 6 | pop(@ch); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 165 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 166 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 167 | 101 | unshift @children, @ch; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 168 | 101 | next; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 169 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 170 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 171 | # semicolon | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 172 | last | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 173 | 389 | ▶ | if $token->isa("PPI::Token::Structure") | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$token->isa("PPI::Token::Structure") and $token->content eq ";"
MC/DC50%1/2
$token->isa("PPI::Token::Structure") and $token->content eq ";"
$token->isa("PPI::Token::Structure")
$token->content eq ";"
Truth table66%2/3
A and B
A= $token->isa("PPI::Token::Structure")B= $token->content eq ";"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 174 | and $token->content eq ';'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 175 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 176 | 311 | ▶ | if ($state eq 'elem') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 177 | 219 | ▶ | if ($token->isa("PPI::Token::QuoteLike::Words")) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 178 | 32 | my @values = qw_to_list($token); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 179 | 32 | push @{$struct}, @values; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 180 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 181 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 182 | 187 | my $value = token_to_string($token); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 183 | 187 | ▶ | last unless defined $value; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 184 | 187 | push @{$struct}, $value; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 185 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 186 | 219 | $state = 'comma'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 187 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 188 | elsif ($state eq 'comma') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 189 | 92 | ▶ | last unless $token->isa("PPI::Token::Operator"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 190 | 92 | ▶ | last unless $token->content =~ /^(?:,|=>)$/; # are there other valid comma-likes? | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 191 | 92 | $state = 'elem'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 192 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 193 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 194 | 0 | die "Sanity check: Unknown state!"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 195 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 196 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 197 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 198 | 134 | return($struct); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 199 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 200 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 201 | # best guess at turning a qw() into a real list | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 202 | 36 | ▶ | sub qw_to_list { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
qw_to_list: called CC=2 SCAR=7.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 203 | 36 | my $token = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 204 | 36 | ▶ | return() if not $token->isa("PPI::Token::QuoteLike::Words"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 205 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 206 | # FIXME This breaks PPI encapsulation, but there seems to be no API! | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 207 | 36 | my $string = substr($token->content, $token->{sections}[0]{position}, $token->{sections}[0]{size}); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 208 | 36 | $string =~ s/^\s+//; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 209 | 36 | $string =~ s/\s+$//; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 210 | 36 | return split /\s+/, $string; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 211 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 212 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 213 | # best guess at turning a token into the string it represents | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 214 | 237 | ▶ | sub token_to_string { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
token_to_string: called CC=4 SCAR=14.1
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 215 | 237 | my $token = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 216 | 237 | ▶ | if ($token->isa("PPI::Token::Quote")) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 217 | 164 | ▶ | return($token->can('literal') ? $token->literal : $token->string); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 218 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 219 | elsif ($token->isa("PPI::Token::HereDoc")) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 220 | 0 | return join '', $token->heredoc; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 221 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 222 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 223 | 73 | return $token->content; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 224 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 225 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 226 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 227 | # Given a PPI token, try to interpret it as a quoted "key" or word (re fat comma) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 228 | 129 | ▶ | sub get_keyname { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
get_keyname: called CC=4 SCAR=14.6
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 229 | 129 | my $token = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 230 | 129 | ▶ | return() unless $token->isa("PPI::Token"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 231 | 129 | ▶ | return $token->content if $token->isa("PPI::Token::Word"); # likely followed by a => | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 232 | 2 | ▶ | return $token->string if $token->isa("PPI::Token::Quote"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 233 | 0 | return(); # TODO: what else makes sense here? | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 234 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 235 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 236 | 7450 | ▶ | sub is_class_method_call { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
is_class_method_call: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 237 | 7450 | my $token = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 238 | 7450 | ▶ | if ($token->isa("PPI::Token::Word")) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 239 | 1156 | return is_method_call($token); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 240 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 241 | 6294 | return(); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 242 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 243 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 244 | 0 | ▶ | sub is_instance_method_call { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
is_instance_method_call: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 245 | 0 | my $token = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 246 | 0 | ▶ | if ($token->isa("PPI::Token::Symbol")) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 247 | 0 | return is_method_call($token); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 248 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 249 | 0 | return(); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 250 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 251 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 252 | 1156 | ▶ | sub is_method_call { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
is_method_call: called CC=10 SCAR=24.5
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 253 | 1156 | my $token = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 254 | 1156 | ▶ | return() unless $token->isa("PPI::Token::Word") or $token->isa("PPI::Token::Symbol"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$token->isa("PPI::Token::Word") or $token->isa("PPI::Token::Symbol")
MC/DC0%0/2
$token->isa("PPI::Token::Word") or $token->isa("PPI::Token::Symbol")
$token->isa("PPI::Token::Word")
$token->isa("PPI::Token::Symbol")
Truth table33%1/3
A or B
A= $token->isa("PPI::Token::Word")B= $token->isa("PPI::Token::Symbol")
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 255 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 256 | 1156 | my $next = $token->snext_sibling(); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 257 | return() | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 258 | 1156 | ▶ | unless $next | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%9/9
$next and $token->content =~ /^[\w:]+$/ and $next->isa("PPI::Token::Operator") and $next->content eq "->"
$next and $token->content =~ /^[\w:]+$/ and $next->isa("PPI::Token::Operator")
$next and $token->content =~ /^[\w:]+$/
MC/DC100%4/4
$next and $token->content =~ /^[\w:]+$/ and $next->isa("PPI::Token::Operator") and $next->content eq "->"
$next
$token->content =~ /^[\w:]+$/
$next->isa("PPI::Token::Operator")
$next->content eq "->"
Truth table100%5/5
A and B and C and D
A= $nextB= $token->content =~ /^[\w:]+$/C= $next->isa("PPI::Token::Operator")D= $next->content eq "->"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 259 | and $token->content =~ /^[\w:]+$/ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 260 | and $next->isa("PPI::Token::Operator") | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 261 | and $next->content eq '->'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 262 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 263 | 12 | my $third = $next->snext_sibling(); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 264 | return() | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 265 | 12 | ▶ | unless defined $third; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 266 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 267 | 12 | ▶ | if ( $third->isa("PPI::Token::Word") or $third->isa("PPI::Token::Symbol") ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$third->isa("PPI::Token::Word") or $third->isa("PPI::Token::Symbol")
MC/DC0%0/2
$third->isa("PPI::Token::Word") or $third->isa("PPI::Token::Symbol")
$third->isa("PPI::Token::Word")
$third->isa("PPI::Token::Symbol")
Truth table33%1/3
A or B
A= $third->isa("PPI::Token::Word")B= $third->isa("PPI::Token::Symbol")
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 268 | 12 | return($token->content(), $third->content()); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 269 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 270 | 0 | return(); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 271 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 272 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 273 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 274 | 9 | 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 275 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 276 | __END__ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||