| 1 | package Perl::Critic::Policy::RegularExpressions::ProhibitRegexInStrings 0.001; | ||||||||||||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||||||||||||
| 3 | # ABSTRACT: Write a regular expression as qr//, not as a string that somebody compiles later. | ||||||||||||||||||||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||||||||||||||||||||
| 5 | 2 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 6 | 2 | ▶ | use warnings FATAL => 'all'; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||||||||||||||||||||
| 8 | 2 | ▶ | use 5.014; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||||||||||||||||||||
| 10 | 2 | ▶ | use re '/aa'; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||||||||||||||||||||
| 12 | 2 | ▶ | use Readonly; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 13 | 2 | ▶ | use PPIx::Regexp; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||||||||||||||||||||
| 15 | 2 | ▶ | use Perl::Critic::Utils qw{ :severities }; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 16 | 2 | ▶ | use parent qw{Perl::Critic::Policy}; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||||||||||||||||||||
| 19 | 2 | Readonly::Scalar my $DESC_KEY => q{Regular expression in a string, as the value of '%s'}; | |||||||||||||||||||||||||||||||||||||||||||||
| 20 | 2 | Readonly::Scalar my $DESC_VAR => q{Regular expression in a string, in %s, which a match uses}; | |||||||||||||||||||||||||||||||||||||||||||||
| 21 | 2 | Readonly::Scalar my $EXPL => q{Write it as qr//, and give "$qr" where a string is needed}; | |||||||||||||||||||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||||||||||||||||||||
| 23 | # A double-quoted string that holds one scalar and nothing else, which is how | ||||||||||||||||||||||||||||||||||||||||||||||
| 24 | # a qr// becomes a string: "$name", "${name}" or "$Package::name". | ||||||||||||||||||||||||||||||||||||||||||||||
| 25 | 2 | Readonly::Scalar my $IDENTIFIER => qr/[[:alpha:]_][[:alnum:]_]*/xs; | |||||||||||||||||||||||||||||||||||||||||||||
| 26 | 2 | Readonly::Scalar my $ONE_SCALAR => qr/\A \$ (?: $IDENTIFIER (?: :: [[:alnum:]_]+ )* | \{ $IDENTIFIER \} ) \z/xs; | |||||||||||||||||||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||||||||||||||||||||
| 28 | # An interpolation in braces, such as ${re}, and the name inside them. | ||||||||||||||||||||||||||||||||||||||||||||||
| 29 | 2 | Readonly::Scalar my $IN_BRACES => qr/\A \$ \{ ([^}]+) \} \z/xs; | |||||||||||||||||||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||||||||||||||||||||
| 31 | 2 | Readonly::Hash my %BINDING => map { $_ => 1 } qw{ =~ !~ }; | |||||||||||||||||||||||||||||||||||||||||||||
| 32 | 2 | Readonly::Hash my %REGEX_TOKEN => map { $_ => 1 } qw{ PPI::Token::Regexp::Match PPI::Token::Regexp::Substitute PPI::Token::QuoteLike::Regexp }; | |||||||||||||||||||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||||||||||||||||||||
| 35 | 3 | ▶ | sub supported_parameters { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
supported_parameters: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 36 | return ( | ||||||||||||||||||||||||||||||||||||||||||||||
| 37 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 38 | 3 | name => 'keys', | |||||||||||||||||||||||||||||||||||||||||||||
| 39 | description => 'The keys whose value is a regular expression', | ||||||||||||||||||||||||||||||||||||||||||||||
| 40 | default_string => 'pattern regex regexp', | ||||||||||||||||||||||||||||||||||||||||||||||
| 41 | behavior => 'string list', | ||||||||||||||||||||||||||||||||||||||||||||||
| 42 | }, | ||||||||||||||||||||||||||||||||||||||||||||||
| 43 | ); | ||||||||||||||||||||||||||||||||||||||||||||||
| 44 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||||||||||||||||||||
| 46 | 25 | ▶ | sub default_severity { return $SEVERITY_MEDIUM } | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
default_severity: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 47 | 0 | ▶ | sub default_themes { return qw{ bugs maintenance } } | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
default_themes: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 48 | 46 | ▶ | sub applies_to { return 'PPI::Token::Quote' } | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
applies_to: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||||||||||||||||||||
| 51 | 50 | ▶ | sub violates { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
violates: called CC=13 SCAR=25.7
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 52 | 50 | my ( $self, $elem, undef ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||||||||||||||||||||
| 54 | # A qr// in a string, which is what this policy asks for. | ||||||||||||||||||||||||||||||||||||||||||||||
| 55 | 50 | ▶ | return if ( $elem->isa('PPI::Token::Quote::Double') || $elem->isa('PPI::Token::Quote::Interpolate') ) && $elem->string =~ $ONE_SCALAR; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%6/6
$elem->isa("PPI::Token::Quote::Double") || $elem->isa("PPI::Token::Quote::Interpolate") and $elem->string =~ /$ONE_SCALAR/aa
$elem->isa("PPI::Token::Quote::Double") or $elem->isa("PPI::Token::Quote::Interpolate")
MC/DC100%3/3
$elem->isa("PPI::Token::Quote::Double") || $elem->isa("PPI::Token::Quote::Interpolate") and $elem->string =~ /$ONE_SCALAR/aa
$elem->isa("PPI::Token::Quote::Double")
$elem->isa("PPI::Token::Quote::Interpolate")
$elem->string =~ /$ONE_SCALAR/aa
Truth table100%5/5
A or B and C
A= $elem->isa("PPI::Token::Quote::Double")B= $elem->isa("PPI::Token::Quote::Interpolate")C= $elem->string =~ /$ONE_SCALAR/aa
| |||||||||||||||||||||||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||||||||||||||||||||
| 57 | 46 | ▶ | my $previous = $elem->sprevious_sibling or return; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 58 | 41 | ▶ | return unless $previous->isa('PPI::Token::Operator'); | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||||||||||||||||||||
| 60 | 40 | ▶ | if ( $previous->content eq '=>' ) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 61 | 17 | ▶ | my $key = $previous->sprevious_sibling or return; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 62 | 17 | ▶ | my $name = $key->isa('PPI::Token::Word') ? $key->content : $key->isa('PPI::Token::Quote') ? $key->string : return; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||
| 63 | 17 | my $keys = $self->{_keys}; | |||||||||||||||||||||||||||||||||||||||||||||
| 64 | 17 | ▶ | return unless $keys->{$name}; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 65 | 13 | return $self->violation( sprintf( $DESC_KEY, $name ), $EXPL, $elem ); | |||||||||||||||||||||||||||||||||||||||||||||
| 66 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||||||||||||||||||||
| 68 | 23 | ▶ | my $name = _declared_scalar($elem) // return; | ||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
_declared_scalar($elem) // (return)
MC/DC100%1/1
_declared_scalar($elem) // (return)
_declared_scalar($elem)
Truth table100%2/2
A
A= _declared_scalar($elem)
| |||||||||||||||||||||||||||||||||||||||||||||||
| 69 | 19 | ▶ | return unless _used_as_regex( $elem->statement, $name ); | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 70 | 12 | return $self->violation( sprintf( $DESC_VAR, $name ), $EXPL, $elem ); | |||||||||||||||||||||||||||||||||||||||||||||
| 71 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||||||||||||||||||||
| 73 | # The name of the one scalar that a declaration sets to the string $quote and | ||||||||||||||||||||||||||||||||||||||||||||||
| 74 | # to nothing else, as a declaration of one lexical does, or undef. | ||||||||||||||||||||||||||||||||||||||||||||||
| 75 | 23 | ▶ | sub _declared_scalar { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_declared_scalar: called CC=11 SCAR=25.6
| |||||||||||||||||||||||||||||||||||||||||||||||
| 76 | 23 | my ($quote) = @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 77 | |||||||||||||||||||||||||||||||||||||||||||||||
| 78 | 23 | my $previous = $quote->sprevious_sibling; | |||||||||||||||||||||||||||||||||||||||||||||
| 79 | 23 | ▶ | return unless $previous && $previous->isa('PPI::Token::Operator') && $previous->content eq q{=}; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition50%3/6
$previous and $previous->isa("PPI::Token::Operator") and $previous->content eq "="
$previous and $previous->isa("PPI::Token::Operator")
MC/DC33%1/3
$previous and $previous->isa("PPI::Token::Operator") and $previous->content eq "="
$previous
$previous->isa("PPI::Token::Operator")
$previous->content eq "="
Truth table50%2/4
A and B and C
A= $previousB= $previous->isa("PPI::Token::Operator")C= $previous->content eq "="
| |||||||||||||||||||||||||||||||||||||||||||||||
| 80 | 21 | my $statement = $quote->statement; | |||||||||||||||||||||||||||||||||||||||||||||
| 81 | 21 | ▶ | return unless $statement && $statement->isa('PPI::Statement::Variable'); | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$statement and $statement->isa("PPI::Statement::Variable")
MC/DC0%0/2
$statement and $statement->isa("PPI::Statement::Variable")
$statement
$statement->isa("PPI::Statement::Variable")
Truth table33%1/3
A and B
A= $statementB= $statement->isa("PPI::Statement::Variable")
| |||||||||||||||||||||||||||||||||||||||||||||||
| 82 | 21 | my @names = $statement->variables; | |||||||||||||||||||||||||||||||||||||||||||||
| 83 | 21 | ▶ | return unless @names == 1 && substr( $names[0], 0, 1 ) eq q{$}; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
@names == 1 and substr($names[0], 0, 1) eq "\$"
MC/DC50%1/2
@names == 1 and substr($names[0], 0, 1) eq "\$"
@names == 1
substr($names[0], 0, 1) eq "\$"
Truth table66%2/3
A and B
A= @names == 1B= substr($names[0], 0, 1) eq "\$"
| |||||||||||||||||||||||||||||||||||||||||||||||
| 84 | 20 | my $next = $quote->snext_sibling; | |||||||||||||||||||||||||||||||||||||||||||||
| 85 | 20 | ▶ | return if $next && !( $next->isa('PPI::Token::Structure') && $next->content eq q{;} ); | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%4/6
$next and not $next->isa("PPI::Token::Structure") && $next->content eq ";"
$next->isa('PPI::Token::Structure') && $next->content eq ';'
MC/DC33%1/3
$next and not $next->isa("PPI::Token::Structure") && $next->content eq ";"
$next
$next->isa('PPI::Token::Structure')
$next->content eq ';'
Truth table50%2/4
A and not(B && C)
A= $nextB= $next->isa('PPI::Token::Structure')C= $next->content eq ';'
| |||||||||||||||||||||||||||||||||||||||||||||||
| 86 | 19 | return $names[0]; | |||||||||||||||||||||||||||||||||||||||||||||
| 87 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||||||||||||||||||||
| 89 | # Whether the block around the statement $declaration uses the scalar $name | ||||||||||||||||||||||||||||||||||||||||||||||
| 90 | # as a regular expression after it, as _regex_use says. | ||||||||||||||||||||||||||||||||||||||||||||||
| 91 | 19 | ▶ | sub _used_as_regex { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_used_as_regex: called CC=3 SCAR=11.1
| |||||||||||||||||||||||||||||||||||||||||||||||
| 92 | 19 | my ( $declaration, $name ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 93 | |||||||||||||||||||||||||||||||||||||||||||||||
| 94 | 19 | ▶ | my $scope = $declaration->parent or return; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 95 | 19 | my $from = _position($declaration); | |||||||||||||||||||||||||||||||||||||||||||||
| 96 | my $found = $scope->find( | ||||||||||||||||||||||||||||||||||||||||||||||
| 97 | 446 | ▶ | sub { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=5 SCAR=16.2
| |||||||||||||||||||||||||||||||||||||||||||||||
| 98 | 446 | my ( undef, $node ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 99 | 446 | my $at = _position($node); | |||||||||||||||||||||||||||||||||||||||||||||
| 100 | 446 | ▶ | return 0 if $at->[0] < $from->[0] || ( $at->[0] == $from->[0] && $at->[1] < $from->[1] ); | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%4/6
$at->[0] < $from->[0] or $at->[0] == $from->[0] and $at->[1] < $from->[1]
$at->[0] == $from->[0] and $at->[1] < $from->[1]
MC/DC33%1/3
$at->[0] < $from->[0] or $at->[0] == $from->[0] and $at->[1] < $from->[1]
$at->[0] < $from->[0]
$at->[0] == $from->[0]
$at->[1] < $from->[1]
Truth table50%2/4
A or B and C
A= $at->[0] < $from->[0]B= $at->[0] == $from->[0]C= $at->[1] < $from->[1]
| |||||||||||||||||||||||||||||||||||||||||||||||
| 101 | 422 | ▶ | return _regex_use( $node, $name ) ? 1 : 0; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 102 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 103 | 19 | ); | |||||||||||||||||||||||||||||||||||||||||||||
| 104 | 19 | ▶ | return $found ? 1 : 0; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 105 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 106 | |||||||||||||||||||||||||||||||||||||||||||||||
| 107 | # Whether the element $node uses the scalar $name as a regular expression: | ||||||||||||||||||||||||||||||||||||||||||||||
| 108 | # interpolated into the expression of a match, a substitution or a qr//, and | ||||||||||||||||||||||||||||||||||||||||||||||
| 109 | # not into the replacement of a substitution; bound with =~ or !~; or the first | ||||||||||||||||||||||||||||||||||||||||||||||
| 110 | # argument of split, with or without parentheses. | ||||||||||||||||||||||||||||||||||||||||||||||
| 111 | 422 | ▶ | sub _regex_use { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_regex_use: called CC=22 SCAR=32.1
| |||||||||||||||||||||||||||||||||||||||||||||||
| 112 | 422 | my ( $node, $name ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 113 | |||||||||||||||||||||||||||||||||||||||||||||||
| 114 | 422 | ▶ | if ( $REGEX_TOKEN{ ref $node } ) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 115 | 8 | ▶ | my $regexp = PPIx::Regexp->new($node) or return; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 116 | 8 | ▶ | my $re = $regexp->regular_expression or return; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 117 | 8 | ▶ | foreach my $interpolation ( @{ $re->find('PPIx::Regexp::Token::Interpolation') || [] } ) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$re->find('PPIx::Regexp::Token::Interpolation') || []
MC/DC100%1/1
$re->find('PPIx::Regexp::Token::Interpolation') || []
$re->find('PPIx::Regexp::Token::Interpolation')
Truth table100%2/2
A
A= $re->find('PPIx::Regexp::Token::Interpolation')
| |||||||||||||||||||||||||||||||||||||||||||||||
| 118 | 4 | my $content = $interpolation->content; | |||||||||||||||||||||||||||||||||||||||||||||
| 119 | 4 | my ($inner) = $content =~ $IN_BRACES; | |||||||||||||||||||||||||||||||||||||||||||||
| 120 | 4 | ▶ | return 1 if ( defined $inner ? "\$$inner" : $content ) eq $name; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||
| 121 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 122 | 4 | return; | |||||||||||||||||||||||||||||||||||||||||||||
| 123 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 124 | |||||||||||||||||||||||||||||||||||||||||||||||
| 125 | 414 | ▶ | return unless $node->isa('PPI::Token::Symbol') && $node->symbol eq $name; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$node->isa("PPI::Token::Symbol") and $node->symbol eq $name
MC/DC100%2/2
$node->isa("PPI::Token::Symbol") and $node->symbol eq $name
$node->isa("PPI::Token::Symbol")
$node->symbol eq $name
Truth table100%3/3
A and B
A= $node->isa("PPI::Token::Symbol")B= $node->symbol eq $name
| |||||||||||||||||||||||||||||||||||||||||||||||
| 126 | 31 | my $before = $node->sprevious_sibling; | |||||||||||||||||||||||||||||||||||||||||||||
| 127 | 31 | ▶ | return 1 if $before && $before->isa('PPI::Token::Operator') && $BINDING{ $before->content }; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%6/6
$before and $before->isa("PPI::Token::Operator") and $BINDING{$before->content}
$before and $before->isa("PPI::Token::Operator")
MC/DC100%3/3
$before and $before->isa("PPI::Token::Operator") and $BINDING{$before->content}
$before
$before->isa("PPI::Token::Operator")
$BINDING{$before->content}
Truth table100%4/4
A and B and C
A= $beforeB= $before->isa("PPI::Token::Operator")C= $BINDING{$before->content}
| |||||||||||||||||||||||||||||||||||||||||||||||
| 128 | 27 | ▶ | return 1 if $before && $before->isa('PPI::Token::Word') && $before->content eq 'split'; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%6/6
$before and $before->isa("PPI::Token::Word") and $before->content eq "split"
$before and $before->isa("PPI::Token::Word")
MC/DC100%3/3
$before and $before->isa("PPI::Token::Word") and $before->content eq "split"
$before
$before->isa("PPI::Token::Word")
$before->content eq "split"
Truth table100%4/4
A and B and C
A= $beforeB= $before->isa("PPI::Token::Word")C= $before->content eq "split"
| |||||||||||||||||||||||||||||||||||||||||||||||
| 129 | 24 | ▶ | return if $before; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 130 | |||||||||||||||||||||||||||||||||||||||||||||||
| 131 | 1 | ▶ | my $list = $node->parent && $node->parent->parent; | ||||||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
$node->parent && $node->parent->parent
MC/DC0%0/2
$node->parent && $node->parent->parent
$node->parent
$node->parent->parent
Truth table33%1/3
A && B
A= $node->parentB= $node->parent->parent
| |||||||||||||||||||||||||||||||||||||||||||||||
| 132 | 1 | ▶ | return unless $list && $list->isa('PPI::Structure::List'); | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$list and $list->isa("PPI::Structure::List")
MC/DC0%0/2
$list and $list->isa("PPI::Structure::List")
$list
$list->isa("PPI::Structure::List")
Truth table33%1/3
A and B
A= $listB= $list->isa("PPI::Structure::List")
| |||||||||||||||||||||||||||||||||||||||||||||||
| 133 | 1 | my $call = $list->sprevious_sibling; | |||||||||||||||||||||||||||||||||||||||||||||
| 134 | 1 | ▶ | return $call && $call->isa('PPI::Token::Word') && $call->content eq 'split'; | ||||||||||||||||||||||||||||||||||||||||||||
|
Condition33%2/6
$call && $call->isa('PPI::Token::Word') && $call->content eq 'split'
$call and $call->isa("PPI::Token::Word")
MC/DC0%0/3
$call && $call->isa('PPI::Token::Word') && $call->content eq 'split'
$call
$call->isa("PPI::Token::Word")
$call->content eq 'split'
Truth table25%1/4
A and B && C
A= $callB= $call->isa("PPI::Token::Word")C= $call->content eq 'split'
| |||||||||||||||||||||||||||||||||||||||||||||||
| 135 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 136 | |||||||||||||||||||||||||||||||||||||||||||||||
| 137 | # The line and the column of $node. | ||||||||||||||||||||||||||||||||||||||||||||||
| 138 | 465 | ▶ | sub _position { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_position: called CC=2 SCAR=7.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 139 | 465 | my ($node) = @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 140 | 465 | ▶ | my $location = $node->location or return [ 0, 0 ]; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 141 | 465 | return [ @{$location}[ 0, 1 ] ]; | |||||||||||||||||||||||||||||||||||||||||||||
| 142 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 143 | |||||||||||||||||||||||||||||||||||||||||||||||
| 144 | 2 | 1; | |||||||||||||||||||||||||||||||||||||||||||||
| 145 | |||||||||||||||||||||||||||||||||||||||||||||||
| 146 | __END__ | ||||||||||||||||||||||||||||||||||||||||||||||