| 1 | package PPIx::EditorTools; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2 | 24 | our $AUTHORITY = 'cpan:YANICK'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 3 | # ABSTRACT: Utility methods and base class for manipulating Perl via PPI | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 4 | 24 | $PPIx::EditorTools::VERSION = '0.20'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 5 | 24 | ▶ | use 5.008; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 6 | 24 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 7 | 24 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 8 | 24 | ▶ | use Carp; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 9 | 24 | use Class::XSAccessor 1.02 constructor => 'new', accessors => { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 10 | 'code' => 'code', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 11 | 'ppi' => 'ppi', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 12 | 24 | ▶ | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 14 | 24 | ▶ | use PPI 1.203; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 15 | 24 | ▶ | use PPIx::EditorTools::ReturnObject; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 18 | # Used by all the PPIx::EditorTools::* modules | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 19 | # Checks for either PPI::Document or take the code as a string and | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 20 | # creates the ppi document | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 22 | sub process_doc { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 23 | 56 | ▶ | my ( $self, %args ) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
process_doc: called CC=7 SCAR=21.3
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 25 | 56 | ▶ | $self->ppi( $args{ppi} ) if defined $args{ppi}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 26 | 56 | ▶ | return 1 if $self->ppi && $self->ppi->isa('PPI::Document'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$self->ppi and $self->ppi->isa("PPI::Document")
MC/DC50%1/2
$self->ppi and $self->ppi->isa("PPI::Document")
$self->ppi
$self->ppi->isa("PPI::Document")
Truth table66%2/3
A and B
A= $self->ppiB= $self->ppi->isa("PPI::Document")
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 28 | # TODO: inefficient to pass around full code/ppi | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 29 | 45 | ▶ | $self->code( $args{code} ) if $args{code}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 30 | 45 | my $code = $self->code; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 31 | 45 | $self->ppi( PPI::Document->new( \$code ) ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 32 | 45 | ▶ | return 1 if $self->ppi && $self->ppi->isa('PPI::Document'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$self->ppi and $self->ppi->isa("PPI::Document")
MC/DC0%0/2
$self->ppi and $self->ppi->isa("PPI::Document")
$self->ppi
$self->ppi->isa("PPI::Document")
Truth table33%1/3
A and B
A= $self->ppiB= $self->ppi->isa("PPI::Document")
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 34 | 0 | croak "arguments ppi or code required"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 35 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 36 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 42 | ##################################################################### | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 43 | # Assorted Search Functions | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 45 | sub find_unmatched_brace { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 46 | 59 | ▶ | $_[1]->isa('PPI::Statement::UnmatchedBrace') and return 1; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
find_unmatched_brace: called CC=5 SCAR=16.3
Pod
undocumented
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 47 | 58 | ▶ | $_[1]->isa('PPI::Structure') or return ''; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 48 | 3 | ▶ | $_[1]->start and $_[1]->finish and return ''; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$_[1]->start and $_[1]->finish
MC/DC50%1/2
$_[1]->start and $_[1]->finish
$_[1]->start
$_[1]->finish
Truth table66%2/3
A and B
A= $_[1]->startB= $_[1]->finish
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 49 | 2 | return 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 50 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 52 | # scans a document for variable declarations and | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 53 | # sorts them into three categories: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 54 | # lexical (my) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 55 | # our (our, doh) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 56 | # dynamic (local) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 57 | # package (use vars) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 58 | # Returns a hash reference containing the three category names | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 59 | # each pointing at a hash which contains '$variablename' => locations. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 60 | # locations is an array reference containing one or more PPI-style | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 61 | # locations. Example: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 62 | # { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 63 | # lexical => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 64 | # '$foo' => [ [ 2, 3, 3], [ 6, 7, 7 ] ], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 65 | # }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 66 | # ... | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 67 | # } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 68 | # Thus, there are two places where a "my $foo" was declared. On line 2 col 3 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 69 | # and line 6 col 7. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 70 | sub get_all_variable_declarations { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 71 | 3 | ▶ | my $document = shift; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
get_all_variable_declarations: called CC=23 SCAR=45.8
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 73 | my $declarations = $document->find( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 74 | sub { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 75 | 55 | ▶ | return 0 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=4 SCAR=13.9
Branch: 1 branch
Condition83%5/6
$_[1]->isa("PPI::Statement::Variable") or $_[1]->isa("PPI::Statement::Include") or $_[1]->isa("PPI::Statement::Compound")
$_[1]->isa("PPI::Statement::Variable") or $_[1]->isa("PPI::Statement::Include")
MC/DC66%2/3
$_[1]->isa("PPI::Statement::Variable") or $_[1]->isa("PPI::Statement::Include") or $_[1]->isa("PPI::Statement::Compound")
$_[1]->isa("PPI::Statement::Variable")
$_[1]->isa("PPI::Statement::Include")
$_[1]->isa("PPI::Statement::Compound")
Truth table75%3/4
A or B or C
A= $_[1]->isa("PPI::Statement::Variable")B= $_[1]->isa("PPI::Statement::Include")C= $_[1]->isa("PPI::Statement::Compound")
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 76 | unless $_[1]->isa('PPI::Statement::Variable') | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 77 | or $_[1]->isa('PPI::Statement::Include') | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 78 | or $_[1]->isa('PPI::Statement::Compound'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 79 | 3 | return 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 80 | }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 81 | 3 | ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 83 | 2 | my %our; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 84 | my %lexical; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 85 | 2 | my %dynamic; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 86 | 2 | my %package; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 87 | 2 | foreach my $decl (@$declarations) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 88 | 3 | ▶ | if ( $decl->isa('PPI::Statement::Variable') ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 89 | 0 | my $type = $decl->type(); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 90 | 0 | my @vars = $decl->variables; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 91 | 0 | my $location = $decl->location; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 92 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 93 | 0 | my $target_type; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 94 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 95 | 0 | ▶ | if ( $type eq 'my' ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 96 | 0 | $target_type = \%lexical; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 97 | } elsif ( $type eq 'our' ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 98 | 0 | $target_type = \%our; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 99 | } elsif ( $type eq 'local' ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 100 | 0 | $target_type = \%dynamic; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 101 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 102 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 103 | 0 | foreach my $var (@vars) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 104 | 0 | ▶ | $target_type->{$var} ||= []; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$target_type->{$var} ||= []
MC/DC0%0/1
$target_type->{$var} ||= []
$target_type->{$var}
Truth table0%0/2
A
A= $target_type->{$var}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 105 | 0 | push @{ $target_type->{$var} }, $location; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 106 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 107 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 108 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 109 | # find use vars... | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 110 | ▶ | elsif ( $decl->isa('PPI::Statement::Include') | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%3/6
$decl->isa("PPI::Statement::Include") and $decl->module eq "vars" and $decl->type eq "use"
$decl->isa("PPI::Statement::Include") and $decl->module eq "vars"
MC/DC0%0/3
$decl->isa("PPI::Statement::Include") and $decl->module eq "vars" and $decl->type eq "use"
$decl->isa("PPI::Statement::Include")
$decl->module eq "vars"
$decl->type eq "use"
Truth table50%2/4
A and B and C
A= $decl->isa("PPI::Statement::Include")B= $decl->module eq "vars"C= $decl->type eq "use"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 111 | and $decl->module eq 'vars' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 112 | and $decl->type eq 'use' ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 113 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 114 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 115 | # do it the low-tech way | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 116 | 0 | my $string = $decl->content(); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 117 | 0 | my $location = $decl->location; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 118 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 119 | 0 | my @vars = $string =~ /([\%\@\$][\w_:]+)/g; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 120 | 0 | foreach my $var (@vars) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 121 | 0 | ▶ | $package{$var} ||= []; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$package{$var} ||= []
MC/DC0%0/1
$package{$var} ||= []
$package{$var}
Truth table0%0/2
A
A= $package{$var}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 122 | 0 | push @{ $package{$var} }, $location; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 123 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 124 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 125 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 126 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 127 | # find for/foreach loop variables | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 128 | ▶ | elsif ( $decl->isa('PPI::Statement::Compound') | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%3/6
$decl->isa("PPI::Statement::Compound") and $decl->type eq "for" || $decl->type eq "foreach"
$decl->type eq "for" or $decl->type eq "foreach"
MC/DC33%1/3
$decl->isa("PPI::Statement::Compound") and $decl->type eq "for" || $decl->type eq "foreach"
$decl->isa("PPI::Statement::Compound")
$decl->type eq "for"
$decl->type eq "foreach"
Truth table50%2/4
A and B or C
A= $decl->isa("PPI::Statement::Compound")B= $decl->type eq "for"C= $decl->type eq "foreach"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 129 | && ( $decl->type eq 'for' or $decl->type eq 'foreach' ) ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 130 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 131 | 2 | my @elems = $decl->elements; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 132 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 133 | 2 | ▶ | next if scalar(@elems) < 5; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 134 | 2 | my $location = $decl->location; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 135 | 2 | my $type = $elems[2]->content(); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 136 | 2 | ▶ | if ( $elems[4]->isa('PPI::Token::Symbol') | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%2/6
$elems[4]->isa("PPI::Token::Symbol") and $type eq "my" || $type eq "our"
$type eq "my" or $type eq "our"
MC/DC0%0/3
$elems[4]->isa("PPI::Token::Symbol") and $type eq "my" || $type eq "our"
$elems[4]->isa("PPI::Token::Symbol")
$type eq "my"
$type eq "our"
Truth table0%0/4
A and B or C
A= $elems[4]->isa("PPI::Token::Symbol")B= $type eq "my"C= $type eq "our"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 137 | && ( $type eq 'my' || $type eq 'our' ) ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 138 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 139 | 2 | my $target_type; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 140 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 141 | # Only my and our are valid for loop variable | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 142 | 2 | ▶ | if ( $type eq 'my' ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 143 | 2 | $target_type = \%lexical; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 144 | } elsif ( $type eq 'our' ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 145 | 0 | $target_type = \%our; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 146 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 147 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 148 | 2 | my $var = $elems[4]->content(); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 149 | 2 | ▶ | $target_type->{$var} ||= []; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$target_type->{$var} ||= []
MC/DC0%0/1
$target_type->{$var} ||= []
$target_type->{$var}
Truth table50%1/2
A
A= $target_type->{$var}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 150 | 2 | push @{ $target_type->{$var} }, $location; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 151 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 152 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 153 | } # end foreach declaration | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 154 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 155 | return ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 156 | 2 | { our => \%our, | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 157 | lexical => \%lexical, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 158 | dynamic => \%dynamic, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 159 | package => \%package | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 160 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 161 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 162 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 163 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 164 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 165 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 166 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 167 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 168 | ##################################################################### | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 169 | # Stuff that should be in PPI itself | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 170 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 171 | sub element_depth { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 172 | 1 | ▶ | my $cursor = shift; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
element_depth: called CC=2 SCAR=10.1
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 173 | 1 | my $depth = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 174 | 1 | ▶ | while ( $cursor = $cursor->parent ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 175 | 0 | $depth += 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 176 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 177 | 0 | return $depth; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 178 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 179 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 180 | # TODO: PPIx::IndexOffsets or something similar might help. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 181 | # TODO: See the 71... tests. If we don#t flush locations there, this breaks. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 182 | sub find_token_at_location { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 183 | 21 | ▶ | my $document = shift; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
find_token_at_location: called CC=9 SCAR=22.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 184 | 21 | my $location = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 185 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 186 | 21 | ▶ | if ( not defined $document | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%6/9
defined $document and $document->isa("PPI::Document") and defined $location and ref $location eq "ARRAY"
defined $document and $document->isa("PPI::Document") and defined $location
defined $document and $document->isa("PPI::Document")
MC/DC25%1/4
defined $document and $document->isa("PPI::Document") and defined $location and ref $location eq "ARRAY"
defined $document
$document->isa("PPI::Document")
defined $location
ref $location eq "ARRAY"
Truth table40%2/5
A and B and C and D
A= defined $documentB= $document->isa("PPI::Document")C= defined $locationD= ref $location eq "ARRAY"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 187 | or not $document->isa('PPI::Document') | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 188 | or not defined $location | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 189 | or not ref($location) eq 'ARRAY' ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 190 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 191 | 1 | require Carp; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 192 | 1 | Carp::croak("find_token_at_location() requires a PPI::Document and a PPI-style location as arguments"); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 193 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 194 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 195 | 20 | $document->index_locations(); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 196 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 197 | 20 | foreach my $token ( $document->tokens ) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 198 | 946 | my $loc = $token->location; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 199 | 946 | ▶ | if ( $loc->[0] > $location->[0] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition83%5/6
$loc->[0] > $location->[0] or $loc->[0] == $location->[0] and $loc->[1] > $location->[1]
$loc->[0] == $location->[0] and $loc->[1] > $location->[1]
MC/DC33%1/3
$loc->[0] > $location->[0] or $loc->[0] == $location->[0] and $loc->[1] > $location->[1]
$loc->[0] > $location->[0]
$loc->[0] == $location->[0]
$loc->[1] > $location->[1]
Truth table50%2/4
A or B and C
A= $loc->[0] > $location->[0]B= $loc->[0] == $location->[0]C= $loc->[1] > $location->[1]
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 200 | or ( $loc->[0] == $location->[0] and $loc->[1] > $location->[1] ) ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 201 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 202 | 20 | $document->flush_locations(); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 203 | 20 | return $token->previous_token(); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 204 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 205 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 206 | 0 | $document->flush_locations(); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 207 | 0 | return (); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 208 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 209 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 210 | # given either a PPI::Token::Symbol (i.e. a variable) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 211 | # or a PPI::Token which contains something that looks like | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 212 | # a variable (quoted vars, interpolated vars in regexes...) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 213 | # find where that variable has been declared lexically. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 214 | # Doesn't find stuff like "use vars...". | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 215 | sub find_variable_declaration { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 216 | 14 | ▶ | my $cursor = shift; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
find_variable_declaration: called CC=33 SCAR=43.5
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 217 | return () | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 218 | 14 | ▶ | if not $cursor | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$cursor and $cursor->isa("PPI::Token")
MC/DC0%0/2
$cursor and $cursor->isa("PPI::Token")
$cursor
$cursor->isa("PPI::Token")
Truth table33%1/3
A and B
A= $cursorB= $cursor->isa("PPI::Token")
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 219 | or not $cursor->isa("PPI::Token"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 220 | 14 | my ( $varname, $token_str ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 221 | 14 | ▶ | if ( $cursor->isa("PPI::Token::Symbol") ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 222 | 14 | $varname = $cursor->symbol; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 223 | 14 | $token_str = $cursor->content; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 224 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 225 | 0 | my $content = $cursor->content; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 226 | 0 | ▶ | if ( $content =~ /((?:\$#?|[@%*])[\w:\']+)/ ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 227 | 0 | $varname = $1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 228 | 0 | $token_str = $1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 229 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 230 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 231 | return () | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 232 | 14 | ▶ | if not defined $varname; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 233 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 234 | 14 | $varname =~ s/^\$\#/@/; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 235 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 236 | 14 | my $document = $cursor->top(); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 237 | 14 | my $declaration; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 238 | my $prev_cursor; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 239 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 240 | # This finds variable declarations if you're above it | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 241 | 14 | ▶ | if ( $cursor->parent->isa('PPI::Statement::Variable') ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 242 | 8 | return $cursor->parent; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 243 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 244 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 245 | # This finds variable declarations if you're above it and it has the form my ($foo , $bar); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 246 | 6 | ▶ | if ( $cursor->parent->isa('PPI::Statement::Expression') | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$cursor->parent->isa("PPI::Statement::Expression") and $cursor->parent->parent->parent->isa("PPI::Statement::Variable")
MC/DC0%0/2
$cursor->parent->isa("PPI::Statement::Expression") and $cursor->parent->parent->parent->isa("PPI::Statement::Variable")
$cursor->parent->isa("PPI::Statement::Expression")
$cursor->parent->parent->parent->isa("PPI::Statement::Variable")
Truth table33%1/3
A and B
A= $cursor->parent->isa("PPI::Statement::Expression")B= $cursor->parent->parent->parent->isa("PPI::Statement::Variable")
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 247 | && $cursor->parent->parent->parent->isa('PPI::Statement::Variable') ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 248 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 249 | 0 | return $cursor->parent->parent->parent; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 250 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 251 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 252 | 6 | while (1) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 253 | 18 | $prev_cursor = $cursor; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 254 | 18 | $cursor = $cursor->parent; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 255 | 18 | ▶ | if ( $cursor->isa("PPI::Structure::Block") or $cursor == $document ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition100%3/3
$cursor->isa("PPI::Structure::Block") or $cursor == $document
MC/DC100%2/2
$cursor->isa("PPI::Structure::Block") or $cursor == $document
$cursor->isa("PPI::Structure::Block")
$cursor == $document
Truth table100%3/3
A or B
A= $cursor->isa("PPI::Structure::Block")B= $cursor == $document
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 256 | 9 | my @elems = $cursor->elements; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 257 | 9 | foreach my $elem (@elems) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 258 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 259 | # Stop scanning this scope if we're at the branch we're coming | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 260 | # from. This is to ignore declarations later in the block. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 261 | 66 | ▶ | last if $elem == $prev_cursor; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 262 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 263 | 63 | ▶ | if ( $elem->isa("PPI::Statement::Variable") | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition100%3/3
$elem->isa("PPI::Statement::Variable") and grep {$_ eq $varname;} $elem->variables
MC/DC100%2/2
$elem->isa("PPI::Statement::Variable") and grep {$_ eq $varname;} $elem->variables
$elem->isa("PPI::Statement::Variable")
grep {$_ eq $varname;} $elem->variables
Truth table100%3/3
A and B
A= $elem->isa("PPI::Statement::Variable")B= grep {$_ eq $varname;} $elem->variables
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 264 | 9 | and grep { $_ eq $varname } $elem->variables ) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 265 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 266 | 6 | $declaration = $elem; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 267 | 6 | last; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 268 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 269 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 270 | # find use vars ... | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 271 | ▶ | elsif ( $elem->isa("PPI::Statement::Include") | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%3/6
$elem->isa("PPI::Statement::Include") and $elem->module eq "vars" and $elem->type eq "use"
$elem->isa("PPI::Statement::Include") and $elem->module eq "vars"
MC/DC0%0/3
$elem->isa("PPI::Statement::Include") and $elem->module eq "vars" and $elem->type eq "use"
$elem->isa("PPI::Statement::Include")
$elem->module eq "vars"
$elem->type eq "use"
Truth table50%2/4
A and B and C
A= $elem->isa("PPI::Statement::Include")B= $elem->module eq "vars"C= $elem->type eq "use"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 272 | and $elem->module eq 'vars' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 273 | and $elem->type eq 'use' ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 274 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 275 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 276 | # do it the low-tech way | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 277 | 0 | my $string = $elem->content(); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 278 | 0 | my @vars = $string =~ /([\%\@\$][\w_:]+)/g; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 279 | 0 | ▶ | if ( grep { $varname eq $_ } @vars ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 280 | 0 | $declaration = $elem; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 281 | 0 | last; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 282 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 283 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 284 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 285 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 286 | 9 | ▶ | last if $declaration or $cursor == $document; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$declaration or $cursor == $document
MC/DC50%1/2
$declaration or $cursor == $document
$declaration
$cursor == $document
Truth table66%2/3
A or B
A= $declarationB= $cursor == $document
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 287 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 288 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 289 | # this is for "foreach my $i ..." | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 290 | ▶ | elsif ( $cursor->isa("PPI::Statement::Compound") | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
$cursor->isa("PPI::Statement::Compound") and $cursor->type =~ /^for/
MC/DC50%1/2
$cursor->isa("PPI::Statement::Compound") and $cursor->type =~ /^for/
$cursor->isa("PPI::Statement::Compound")
$cursor->type =~ /^for/
Truth table66%2/3
A and B
A= $cursor->isa("PPI::Statement::Compound")B= $cursor->type =~ /^for/
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 291 | and $cursor->type() =~ /^for/ ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 292 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 293 | 3 | my @elems = $cursor->elements; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 294 | 3 | foreach my $elem (@elems) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 295 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 296 | # Stop scanning this scope if we're at the branch we're coming | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 297 | # from. This is to ignore declarations later in the block. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 298 | 27 | ▶ | last if $elem == $prev_cursor; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 299 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 300 | 24 | ▶ | if ( $elem->isa("PPI::Token::Word") | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$elem->isa("PPI::Token::Word") and $elem->content =~ /^(?:my|our)$/
MC/DC100%2/2
$elem->isa("PPI::Token::Word") and $elem->content =~ /^(?:my|our)$/
$elem->isa("PPI::Token::Word")
$elem->content =~ /^(?:my|our)$/
Truth table100%3/3
A and B
A= $elem->isa("PPI::Token::Word")B= $elem->content =~ /^(?:my|our)$/
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 301 | and $elem->content() =~ /^(?:my|our)$/ ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 302 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 303 | 3 | my $nelem = $elem->snext_sibling(); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 304 | 3 | ▶ | if ( defined $nelem | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%3/9
defined $nelem and $nelem->isa("PPI::Token::Symbol") and $nelem->symbol eq $varname || $nelem->content eq $token_str
defined $nelem and $nelem->isa("PPI::Token::Symbol")
$nelem->symbol eq $varname or $nelem->content eq $token_str
MC/DC0%0/4
defined $nelem and $nelem->isa("PPI::Token::Symbol") and $nelem->symbol eq $varname || $nelem->content eq $token_str
defined $nelem
$nelem->isa("PPI::Token::Symbol")
$nelem->symbol eq $varname
$nelem->content eq $token_str
Truth table20%1/5
A and B and C or D
A= defined $nelemB= $nelem->isa("PPI::Token::Symbol")C= $nelem->symbol eq $varnameD= $nelem->content eq $token_str
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 305 | and $nelem->isa("PPI::Token::Symbol") | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 306 | and $nelem->symbol() eq $varname || $nelem->content() eq $token_str ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 307 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 308 | 0 | $declaration = $nelem; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 309 | 0 | last; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 310 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 311 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 312 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 313 | 3 | ▶ | last if $declaration or $cursor == $document; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$declaration or $cursor == $document
MC/DC0%0/2
$declaration or $cursor == $document
$declaration
$cursor == $document
Truth table33%1/3
A or B
A= $declarationB= $cursor == $document
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 314 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 315 | } # end while not top level | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 316 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 317 | 6 | return $declaration; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 318 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 319 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 320 | 24 | 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 321 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 322 | =pod | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 323 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 324 | =encoding UTF-8 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 325 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 326 | =head1 NAME | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 327 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 328 | PPIx::EditorTools - Utility methods and base class for manipulating Perl via PPI | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 329 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 330 | =head1 VERSION | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 331 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 332 | version 0.20 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 333 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 334 | =head1 SYNOPSIS | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 335 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 336 | See PPIx::EditorTools::* | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 337 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 338 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 339 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 340 | Base class and utility methods for manipulating Perl via PPI. Pulled out from | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 341 | the C<Padre::Task::PPI> code. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 342 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 343 | =head1 METHODS | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 344 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 345 | =over 4 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 346 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 347 | =item new() | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 348 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 349 | Constructor. Generally shouldn't be called with any arguments. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 350 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 351 | =back | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 352 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 353 | =head1 SEE ALSO | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 354 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 355 | C<PPIx::EditorTools::*>, L<Padre>, L<App::EditorTools>, L<Padre>, and L<PPI>. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 356 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 357 | =head1 AUTHORS | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 358 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 359 | =over 4 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 360 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 361 | =item * | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 362 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 363 | Steffen Mueller C<smueller@cpan.org> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 364 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 365 | =item * | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 366 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 367 | Mark Grimes C<mgrimes@cpan.org> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 368 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 369 | =item * | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 370 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 371 | Ahmad M. Zawawi <ahmad.zawawi@gmail.com> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 372 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 373 | =item * | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 374 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 375 | Gabor Szabo <gabor@szabgab.com> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 376 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 377 | =item * | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 378 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 379 | Yanick Champoux <yanick@cpan.org> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 380 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 381 | =back | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 382 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 383 | =head1 COPYRIGHT AND LICENSE | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 384 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 385 | This software is copyright (c) 2017, 2014, 2012 by The Padre development team as listed in Padre.pm.. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 386 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 387 | This is free software; you can redistribute it and/or modify it under | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 388 | the same terms as the Perl 5 programming language system itself. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 389 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 390 | =cut | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 391 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 392 | __END__ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 393 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 394 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 395 | # Copyright 2008-2009 The Padre development team as listed in Padre.pm. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 396 | # LICENSE | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 397 | # This program is free software; you can redistribute it and/or | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 398 | # modify it under the same terms as Perl 5 itself. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||