| 1 | package Perl::Critic::Policy::RegularExpressions::ProhibitIneffectiveModifiers 0.001; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 3 | # ABSTRACT: Write a regex modifier only where it changes what the regex does. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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 List::Util qw{ any }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 13 | 2 | ▶ | use Readonly; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
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 $EXPL => q{Remove the modifier, which changes nothing here}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 21 | 2 | Readonly::Hash my %DESC => ( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 22 | g => q{Modifier /g on a regex that can match only once}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 23 | i => q{Modifier /i on a regex with nothing that has a case}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 24 | m => q{Modifier /m on a regex with no ^ or $}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 25 | o => q{Modifier /o on a regex with nothing to interpolate}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 26 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 28 | 2 | Readonly::Scalar my $NEWLINE => 10; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 30 | # Larger ranges are taken to hold a character with a case, rather than read. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 31 | 2 | Readonly::Scalar my $RANGE_LIMIT => 1024; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 33 | 2 | Readonly::Hash my %START => map { $_ => 1 } ( '\A', '^' ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 35 | # Single-character classes that never match a newline, and so cannot be all of | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 36 | # a second match before the final one. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 37 | 2 | Readonly::Hash my %NOT_A_NEWLINE => map { $_ => 1 } ( '\w', '\d', '\S', '\N', '\V', '\h' ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 39 | # The tokens that are the same with and without /i. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 40 | 2 | Readonly::Array my @CASELESS_TOKENS => map { "PPIx::Regexp::Token::$_" } qw{ | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 41 | Assertion Quantifier Greediness Whitespace Comment Operator GroupType Structure Delimiter Modifier | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 42 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 45 | 2 | ▶ | sub supported_parameters { return () } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
supported_parameters: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 46 | 39 | ▶ | sub default_severity { return $SEVERITY_LOW } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
default_severity: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 47 | 0 | ▶ | sub default_themes { return qw{ maintenance } } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
default_themes: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 48 | 80 | ▶ | sub applies_to { return qw{ PPI::Token::Regexp::Match PPI::Token::Regexp::Substitute PPI::Token::QuoteLike::Regexp } } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
applies_to: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 51 | 81 | ▶ | sub violates { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
violates: called CC=9 SCAR=22.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 52 | 81 | my ( $self, $elem, $doc ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 54 | 81 | my %written = $elem->get_modifiers; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 55 | 81 | ▶ | return unless any { $written{$_} } keys %DESC; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 57 | # From the document rather than PPIx::Regexp->new, so that a use re in | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 58 | # scope counts toward what ^, $ and . mean. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 59 | 74 | ▶ | my $regexp = $doc->ppix_regexp_from_element($elem) or return; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 60 | 74 | ▶ | my $re = $regexp->regular_expression or return; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 62 | 74 | my $interpolates = $re->find_first('PPIx::Regexp::Token::Interpolation'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 63 | my %ineffective = ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 64 | 74 | ▶ | g => !!( !$interpolates && !$written{c} && _matches_once($re) ), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%12/12
!($interpolates || $written{'c'}) && _matches_once($re)
$interpolates || $written{'c'}
!$interpolates && _is_caseless($re)
$interpolates || _has_line_anchor($re)
MC/DC100%3/3
!($interpolates || $written{'c'}) && _matches_once($re)
$interpolates
$written{'c'}
_matches_once($re)
MC/DC100%2/2
!$interpolates && _is_caseless($re)
!$interpolates
_is_caseless($re)
MC/DC100%2/2
$interpolates || _has_line_anchor($re)
$interpolates
_has_line_anchor($re)
Truth table100%4/4
not(A || B) && C
A= $interpolatesB= $written{'c'}C= _matches_once($re)
Truth table100%3/3
not(A) && B
A= !$interpolatesB= _is_caseless($re)
Truth table100%3/3
A || B
A= $interpolatesB= _has_line_anchor($re)
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 65 | i => !!( !$interpolates && _is_caseless($re) ), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 66 | m => !!( !$interpolates && !_has_line_anchor($re) ), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 67 | o => !$interpolates, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 68 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 70 | 74 | ▶ | return map { $self->violation( $DESC{$_}, $EXPL, $elem ) } grep { $written{$_} && $ineffective{$_} } sort keys %DESC; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%3/3
$written{$_} && $ineffective{$_}
MC/DC100%2/2
$written{$_} && $ineffective{$_}
$written{$_}
$ineffective{$_}
Truth table100%3/3
A && B
A= $written{$_}B= $ineffective{$_}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 71 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 73 | # Whether the pattern can match at most once: anchored at the start, or at an | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 74 | # end that only one match can reach. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 75 | 65 | ▶ | sub _matches_once { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_matches_once: called CC=9 SCAR=22.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 76 | 65 | my ($re) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 77 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 78 | 65 | my @parts = _significant( $re->children ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 79 | 65 | ▶ | return if _alternates(@parts); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 80 | 64 | ▶ | return 1 if _is_start( $parts[0] ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 81 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 82 | 53 | my $end = pop @parts; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 83 | 53 | ▶ | return unless $end && $end->isa('PPIx::Regexp::Token::Assertion'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$end and $end->isa("PPIx::Regexp::Token::Assertion")
MC/DC50%1/2
$end and $end->isa("PPIx::Regexp::Token::Assertion")
$end
$end->isa("PPIx::Regexp::Token::Assertion")
Truth table66%2/3
A and B
A= $endB= $end->isa("PPIx::Regexp::Token::Assertion")
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 84 | 23 | ▶ | return _consumes( \@parts, \&_is_a_character ) if $end->content eq '\z'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 85 | 15 | ▶ | my $before_a_final_newline = $end->content eq '\Z' || ( $end->content eq '$' && !$end->modifier_asserted('m') ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition83%5/6
$end->content eq '\\Z' || $end->content eq '$' && !$end->modifier_asserted('m')
$end->content eq "\$" and not $end->modifier_asserted("m")
MC/DC66%2/3
$end->content eq '\\Z' || $end->content eq '$' && !$end->modifier_asserted('m')
$end->content eq '\\Z'
$end->content eq "\$"
not $end->modifier_asserted("m")
Truth table75%3/4
A || B and not(C)
A= $end->content eq '\\Z'B= $end->content eq "\$"C= not $end->modifier_asserted("m")
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 86 | 15 | ▶ | return unless $before_a_final_newline; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 87 | 9 | return _consumes( \@parts, \&_is_not_a_newline ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 88 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 89 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 90 | # Whether $part anchors the start of the string. Under /m, ^ anchors any line. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 91 | 64 | ▶ | sub _is_start { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_is_start: called CC=5 SCAR=16.1
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 92 | 64 | my ($part) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 93 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 94 | 64 | ▶ | return unless $part && $part->isa('PPIx::Regexp::Token::Assertion') && $START{ $part->content }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition83%5/6
$part and $part->isa("PPIx::Regexp::Token::Assertion") and $START{$part->content}
$part and $part->isa("PPIx::Regexp::Token::Assertion")
MC/DC66%2/3
$part and $part->isa("PPIx::Regexp::Token::Assertion") and $START{$part->content}
$part
$part->isa("PPIx::Regexp::Token::Assertion")
$START{$part->content}
Truth table75%3/4
A and B and C
A= $partB= $part->isa("PPIx::Regexp::Token::Assertion")C= $START{$part->content}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 95 | 18 | ▶ | return $part->content eq '\A' || !$part->modifier_asserted('m'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%3/3
$part->content eq '\\A' || !$part->modifier_asserted('m')
MC/DC100%2/2
$part->content eq '\\A' || !$part->modifier_asserted('m')
$part->content eq '\\A'
!$part->modifier_asserted('m')
Truth table100%3/3
A || not(B)
A= $part->content eq '\\A'B= !$part->modifier_asserted('m')
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 96 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 97 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 98 | # Whether some part of @$parts has to match at least once, and matches a | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 99 | # character for which $matches is true. A group counts if its own parts do. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 100 | 18 | ▶ | sub _consumes { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_consumes: called CC=8 SCAR=20.8
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 101 | 18 | my ( $parts, $matches ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 102 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 103 | 18 | my @parts = @$parts; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 104 | 18 | foreach my $at ( 0 .. $#parts ) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 105 | 21 | ▶ | next if _may_repeat_zero( $parts[ $at + 1 ] ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 106 | 18 | my $part = $parts[$at]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 107 | 18 | ▶ | if ( $part->isa('PPIx::Regexp::Structure::Capture') || $part->isa('PPIx::Regexp::Structure::Modifier') ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$part->isa("PPIx::Regexp::Structure::Capture") or $part->isa("PPIx::Regexp::Structure::Modifier")
MC/DC100%2/2
$part->isa("PPIx::Regexp::Structure::Capture") or $part->isa("PPIx::Regexp::Structure::Modifier")
$part->isa("PPIx::Regexp::Structure::Capture")
$part->isa("PPIx::Regexp::Structure::Modifier")
Truth table100%3/3
A or B
A= $part->isa("PPIx::Regexp::Structure::Capture")B= $part->isa("PPIx::Regexp::Structure::Modifier")
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 108 | 2 | my @inner = _significant( $part->children ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 109 | 2 | ▶ | return 1 if !_alternates(@inner) && _consumes( \@inner, $matches ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
not _alternates(@inner) and _consumes(\@inner, $matches)
MC/DC50%1/2
not _alternates(@inner) and _consumes(\@inner, $matches)
not _alternates(@inner)
_consumes(\@inner, $matches)
Truth table66%2/3
not(A) and B
A= not _alternates(@inner)B= _consumes(\@inner, $matches)
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 110 | 1 | next; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 111 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 112 | 16 | ▶ | return 1 if $matches->($part); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 113 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 114 | 8 | return; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 115 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 116 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 117 | # Whether $next is a quantifier that lets the part before it match no times. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 118 | 21 | ▶ | sub _may_repeat_zero { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_may_repeat_zero: called CC=4 SCAR=13.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 119 | 21 | my ($next) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 120 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 121 | 21 | ▶ | return unless $next; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 122 | 8 | ▶ | return $next->content ne '+' if $next->isa('PPIx::Regexp::Token::Quantifier'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 123 | 3 | ▶ | return unless $next->isa('PPIx::Regexp::Structure::Quantifier'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 124 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 125 | 2 | my ($least) = $next->content =~ m/\A[{]\s*(\d*)/sx; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 126 | 2 | return !$least; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 127 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 128 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 129 | # Whether $part matches one character, whatever it is. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 130 | 7 | ▶ | sub _is_a_character { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_is_a_character: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 131 | 7 | my ($part) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 132 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 133 | 7 | ▶ | return any { $part->isa("PPIx::Regexp::$_") } qw{ Token::Literal Token::CharClass::Simple Structure::CharClass }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 134 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 135 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 136 | # Whether $part matches one character, and never a newline. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 137 | 9 | ▶ | sub _is_not_a_newline { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_is_not_a_newline: called CC=6 SCAR=18.2
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 138 | 9 | my ($part) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 139 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 140 | 9 | ▶ | return ( $part->ordinal // $NEWLINE ) != $NEWLINE if $part->isa('PPIx::Regexp::Token::Literal'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$part->ordinal // $NEWLINE
MC/DC0%0/2
$part->ordinal // $NEWLINE
$part->ordinal
$NEWLINE
Truth table33%1/3
A // B
A= $part->ordinalB= $NEWLINE
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 141 | 5 | ▶ | return unless $part->isa('PPIx::Regexp::Token::CharClass::Simple'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 142 | 3 | ▶ | return 1 if $NOT_A_NEWLINE{ $part->content }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 143 | 2 | ▶ | return $part->content eq '.' && !$part->modifier_asserted('s'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
$part->content eq '.' && !$part->modifier_asserted('s')
MC/DC0%0/2
$part->content eq '.' && !$part->modifier_asserted('s')
$part->content eq '.'
!$part->modifier_asserted('s')
Truth table66%2/3
A && not(B)
A= $part->content eq '.'B= !$part->modifier_asserted('s')
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 144 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 145 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 146 | # Whether nothing in the pattern is changed by /i. Anything the policy does | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 147 | # not know to be caseless is taken to have a case. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 148 | 66 | ▶ | sub _is_caseless { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_is_caseless: called CC=16 SCAR=28.2
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 149 | 66 | my ($re) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 150 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 151 | 66 | ▶ | foreach my $range ( @{ $re->find('PPIx::Regexp::Node::Range') || [] } ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$re->find('PPIx::Regexp::Node::Range') || []
MC/DC100%1/1
$re->find('PPIx::Regexp::Node::Range') || []
$re->find('PPIx::Regexp::Node::Range')
Truth table100%2/2
A
A= $re->find('PPIx::Regexp::Node::Range')
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 152 | 4 | my ( $from, $to ) = map { $_->ordinal } grep { $_->isa('PPIx::Regexp::Token::Literal') } $range->children; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 153 | 4 | ▶ | return if !defined $from || !defined $to || $to - $from >= $RANGE_LIMIT; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%2/6
not defined $from && defined $to or $to - $from >= $RANGE_LIMIT
defined $from && defined $to
MC/DC0%0/3
not defined $from && defined $to or $to - $from >= $RANGE_LIMIT
defined $from
defined $to
$to - $from >= $RANGE_LIMIT
Truth table25%1/4
not(A && B) or C
A= defined $fromB= defined $toC= $to - $from >= $RANGE_LIMIT
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 154 | 4 | ▶ | return unless _all_caseless( $from .. $to ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 155 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 156 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 157 | 64 | foreach my $token ( $re->tokens ) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 158 | 248 | ▶ | next if any { $token->isa($_) } @CASELESS_TOKENS; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 159 | 71 | ▶ | next if $token->isa('PPIx::Regexp::Token::Control') && $token->content =~ m/\A\\[QE]\z/sx; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$token->isa("PPIx::Regexp::Token::Control") and $token->content =~ /\A\\[QE]\z/aasx
MC/DC50%1/2
$token->isa("PPIx::Regexp::Token::Control") and $token->content =~ /\A\\[QE]\z/aasx
$token->isa("PPIx::Regexp::Token::Control")
$token->content =~ /\A\\[QE]\z/aasx
Truth table66%2/3
A and B
A= $token->isa("PPIx::Regexp::Token::Control")B= $token->content =~ /\A\\[QE]\z/aasx
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 160 | 69 | ▶ | next if $token->isa('PPIx::Regexp::Token::CharClass::Simple') && $token->content !~ m/\A\\[pP]/sx; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$token->isa("PPIx::Regexp::Token::CharClass::Simple") and not $token->content =~ /\A\\[pP]/aasx
MC/DC100%2/2
$token->isa("PPIx::Regexp::Token::CharClass::Simple") and not $token->content =~ /\A\\[pP]/aasx
$token->isa("PPIx::Regexp::Token::CharClass::Simple")
not $token->content =~ /\A\\[pP]/aasx
Truth table100%3/3
A and not(B)
A= $token->isa("PPIx::Regexp::Token::CharClass::Simple")B= not $token->content =~ /\A\\[pP]/aasx
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 161 | 47 | ▶ | return unless $token->isa('PPIx::Regexp::Token::Literal'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 162 | 45 | my $ordinal = $token->ordinal; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 163 | 45 | ▶ | return unless defined $ordinal && _all_caseless($ordinal); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
defined $ordinal and _all_caseless($ordinal)
MC/DC50%1/2
defined $ordinal and _all_caseless($ordinal)
defined $ordinal
_all_caseless($ordinal)
Truth table66%2/3
A and B
A= defined $ordinalB= _all_caseless($ordinal)
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 164 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 165 | 31 | return 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 166 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 167 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 168 | # Whether each of the characters @ordinals is its own upper and lower case. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 169 | 49 | ▶ | sub _all_caseless { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_all_caseless: called CC=4 SCAR=13.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 170 | 49 | my (@ordinals) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 171 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 172 | 49 | foreach my $character ( map { chr } @ordinals ) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 173 | 121 | ▶ | return if lc $character ne $character || uc $character ne $character; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
lc $character ne $character or uc $character ne $character
MC/DC100%2/2
lc $character ne $character or uc $character ne $character
lc $character ne $character
uc $character ne $character
Truth table100%3/3
A or B
A= lc $character ne $characterB= uc $character ne $character
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 174 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 175 | 16 | return 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 176 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 177 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 178 | # Whether ^ or $ is anywhere in the pattern, which is all that /m changes. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 179 | 66 | ▶ | sub _has_line_anchor { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_has_line_anchor: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 180 | 66 | my ($re) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 181 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 182 | 66 | ▶ | return any { $_->content eq '^' || $_->content eq '$' } @{ $re->find('PPIx::Regexp::Token::Assertion') || [] }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=6.9
Branch: 1 branch
Condition100%2/2
$re->find('PPIx::Regexp::Token::Assertion') || []
MC/DC100%1/1
$re->find('PPIx::Regexp::Token::Assertion') || []
$re->find('PPIx::Regexp::Token::Assertion')
Truth table100%2/2
A
A= $re->find('PPIx::Regexp::Token::Assertion')
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 183 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 184 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 185 | # Whether @parts holds an alternation at its own level. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 186 | 67 | ▶ | sub _alternates { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_alternates: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 187 | 67 | my (@parts) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 188 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 189 | 67 | ▶ | return any { $_->isa('PPIx::Regexp::Token::Operator') && $_->content eq '|' } @parts; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=6.9
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 190 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 191 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 192 | # The parts of a pattern that match something: whitespace and comments under | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 193 | # /x do not. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 194 | 67 | ▶ | sub _significant { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_significant: called CC=2 SCAR=7.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 195 | 67 | my (@parts) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 196 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 197 | 67 | ▶ | return grep { !$_->isa('PPIx::Regexp::Token::Whitespace') && !$_->isa('PPIx::Regexp::Token::Comment') } @parts; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
$_->isa('PPIx::Regexp::Token::Whitespace') || $_->isa('PPIx::Regexp::Token::Comment')
MC/DC50%1/2
$_->isa('PPIx::Regexp::Token::Whitespace') || $_->isa('PPIx::Regexp::Token::Comment')
$_->isa('PPIx::Regexp::Token::Whitespace')
$_->isa('PPIx::Regexp::Token::Comment')
Truth table66%2/3
A || B
A= $_->isa('PPIx::Regexp::Token::Whitespace')B= $_->isa('PPIx::Regexp::Token::Comment')
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 198 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 199 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 200 | 2 | 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 201 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 202 | __END__ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||