| 1 | package Perl::Critic::Policy::RegularExpressions::ProhibitRegexToSplitAtDelimiter 0.001; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 3 | # ABSTRACT: Find the first literal separator with index and substr, not a regex. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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 $DESC => q{Regex used to find the first literal separator}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 21 | # The replacement for each form, by whether it substitutes in place or in a | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 22 | # copy, and then whether it captures. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 23 | 2 | Readonly::Hash my %EXPL => ( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 24 | match => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 25 | capture => q{Find the separator with index(), then take the text before it with substr()}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 26 | none => q{Ask whether the separator is there with index() >= 0}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 27 | }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 28 | substitute => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 29 | capture => q{Find the separator with index(), then take the text and the separator off with four-argument substr() and an empty replacement}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 30 | none => q{Find the separator with index(), then take everything up to and including it off with four-argument substr() and an empty replacement}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 31 | }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 32 | copy => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 33 | capture => q{Find the separator with index(), then take the text before it and the text after it with substr()}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 34 | none => q{Find the separator with index(), then take the text after it with substr()}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 35 | }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 36 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 38 | 2 | Readonly::Scalar my $NEWLINE => 10; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 40 | # Modifiers that change what the pattern does in a way index cannot follow: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 41 | # /i compares without case, /g iterates. /m is handled at the anchor, since | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 42 | # it matters only to ^, and /s at the dot. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 43 | 2 | Readonly::Array my @EXEMPTING_MODIFIERS => qw{ i g }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 45 | # The quantifiers that still mean "all of it, up to the separator". | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 46 | 2 | Readonly::Hash my %QUANTIFIER => map { $_ => 1 } qw{ * + }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 48 | # The controls that quote what is between them, which a separator may sit in. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 49 | 2 | Readonly::Hash my %QUOTING => map { $_ => 1 } ( '\Q', '\E' ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 52 | 2 | ▶ | sub supported_parameters { return () } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
supported_parameters: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 53 | 54 | ▶ | sub default_severity { return $SEVERITY_MEDIUM } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
default_severity: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 54 | 0 | ▶ | sub default_themes { return qw{ performance maintenance } } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
default_themes: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 55 | 107 | ▶ | sub applies_to { return qw{ PPI::Token::Regexp::Match PPI::Token::Regexp::Substitute } } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
applies_to: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 58 | 104 | ▶ | sub violates { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
violates: called CC=13 SCAR=25.7
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 59 | 104 | my ( $self, $elem, $doc ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 61 | 104 | my $substitute = $elem->isa('PPI::Token::Regexp::Substitute'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 62 | 104 | ▶ | return if $substitute && $elem->get_substitute_string ne q{}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$substitute and $elem->get_substitute_string ne ""
MC/DC100%2/2
$substitute and $elem->get_substitute_string ne ""
$substitute
$elem->get_substitute_string ne ""
Truth table100%3/3
A and B
A= $substituteB= $elem->get_substitute_string ne ""
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 64 | # From the document rather than PPIx::Regexp->new, so that the modifiers of | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 65 | # a use re in scope are asserted as well as the ones written on the regex. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 66 | 102 | ▶ | my $regexp = $doc->ppix_regexp_from_element($elem) or return; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 67 | 102 | ▶ | return if any { $regexp->modifier_asserted($_) } @EXEMPTING_MODIFIERS; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 69 | 96 | ▶ | my $captures = $regexp->max_capture_number // 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$regexp->max_capture_number // 0
MC/DC0%0/1
$regexp->max_capture_number // 0
$regexp->max_capture_number
Truth table50%1/2
A
A= $regexp->max_capture_number
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 71 | 96 | ▶ | my $re = $regexp->regular_expression or return; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 72 | 96 | my @parts = _significant( $re->children ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 73 | 96 | ▶ | return unless _is_start( shift @parts ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 74 | 90 | ▶ | return unless $captures ? _captures_before_a_separator( \@parts ) : _runs_to_a_separator( \@parts ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 76 | 54 | ▶ | my $form = !$substitute ? 'match' : $regexp->modifier_asserted('r') ? 'copy' : 'substitute'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 77 | 54 | ▶ | my $expl = $EXPL{$form}{ $captures ? 'capture' : 'none' }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 78 | 54 | return $self->violation( $DESC, $expl, $elem ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 79 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 81 | # Whether @$parts, after the anchor, is one capture of everything before the | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 82 | # separator, and the separator, with nothing after it. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 83 | 58 | ▶ | sub _captures_before_a_separator { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_captures_before_a_separator: called CC=4 SCAR=14.5
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 84 | 58 | my ($parts) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 86 | 58 | my ( $capture, @separator ) = @$parts; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 87 | 58 | ▶ | return unless $capture && $capture->isa('PPIx::Regexp::Structure::Capture'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$capture and $capture->isa("PPIx::Regexp::Structure::Capture")
MC/DC0%0/2
$capture and $capture->isa("PPIx::Regexp::Structure::Capture")
$capture
$capture->isa("PPIx::Regexp::Structure::Capture")
Truth table33%1/3
A and B
A= $captureB= $capture->isa("PPIx::Regexp::Structure::Capture")
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 89 | 58 | ▶ | my @ordinals = _literal_ordinals(@separator) or return; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 90 | 46 | return _is_everything_before( [ _significant( $capture->children ) ], \@ordinals ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 91 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 92 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 93 | # Whether @$parts, after the anchor, is the same run of everything before the | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 94 | # separator with no capture around it, and the separator. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 95 | 32 | ▶ | sub _runs_to_a_separator { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_runs_to_a_separator: called CC=4 SCAR=13.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 96 | 32 | my ($parts) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 97 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 98 | 32 | my ( $atom, $quantifier, @separator ) = @$parts; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 99 | 32 | my @run = ( $atom, $quantifier ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 100 | 32 | ▶ | push @run, shift @separator if @separator && $separator[0]->isa('PPIx::Regexp::Token::Greediness'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
@separator and $separator[0]->isa("PPIx::Regexp::Token::Greediness")
MC/DC100%2/2
@separator and $separator[0]->isa("PPIx::Regexp::Token::Greediness")
@separator
$separator[0]->isa("PPIx::Regexp::Token::Greediness")
Truth table100%3/3
A and B
A= @separatorB= $separator[0]->isa("PPIx::Regexp::Token::Greediness")
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 101 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 102 | 32 | ▶ | my @ordinals = _literal_ordinals(@separator) or return; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 103 | 23 | return _is_everything_before( \@run, \@ordinals ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 104 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 105 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 106 | # Whether $part anchors the start of the string. Under /m, ^ anchors any line. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 107 | 96 | ▶ | sub _is_start { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_is_start: called CC=5 SCAR=16.2
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 108 | 96 | my ($part) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 109 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 110 | 96 | ▶ | return unless $part && $part->isa('PPIx::Regexp::Token::Assertion'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$part and $part->isa("PPIx::Regexp::Token::Assertion")
MC/DC50%1/2
$part and $part->isa("PPIx::Regexp::Token::Assertion")
$part
$part->isa("PPIx::Regexp::Token::Assertion")
Truth table66%2/3
A and B
A= $partB= $part->isa("PPIx::Regexp::Token::Assertion")
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 111 | 93 | my $anchor = $part->content; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 112 | 93 | ▶ | return 1 if $anchor eq '\A'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 113 | 5 | ▶ | return $anchor eq '^' && !$part->modifier_asserted('m'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
$anchor eq '^' && !$part->modifier_asserted('m')
MC/DC50%1/2
$anchor eq '^' && !$part->modifier_asserted('m')
$anchor eq '^'
!$part->modifier_asserted('m')
Truth table66%2/3
A && not(B)
A= $anchor eq '^'B= !$part->modifier_asserted('m')
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 114 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 115 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 116 | # The characters @parts match, in order, if each part is one literal character | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 117 | # or a class of one, between an optional \Q and \E; otherwise nothing. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 118 | 90 | ▶ | sub _literal_ordinals { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_literal_ordinals: called CC=4 SCAR=13.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 119 | 90 | my (@separator) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 120 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 121 | 90 | ▶ | my @parts = grep { !( $_->isa('PPIx::Regexp::Token::Control') && $QUOTING{ $_->content } ) } @separator; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
$_->isa('PPIx::Regexp::Token::Control') && $QUOTING{$_->content}
MC/DC50%1/2
$_->isa('PPIx::Regexp::Token::Control') && $QUOTING{$_->content}
$_->isa('PPIx::Regexp::Token::Control')
$QUOTING{$_->content}
Truth table66%2/3
A && B
A= $_->isa('PPIx::Regexp::Token::Control')B= $QUOTING{$_->content}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 122 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 123 | 90 | my @ordinals = map { _ordinal($_) } @parts; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 124 | 90 | ▶ | return unless @ordinals && @ordinals == @parts; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
@ordinals and @ordinals == @parts
MC/DC100%2/2
@ordinals and @ordinals == @parts
@ordinals
@ordinals == @parts
Truth table100%3/3
A and B
A= @ordinalsB= @ordinals == @parts
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 125 | 69 | return @ordinals; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 126 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 127 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 128 | # The character $part matches, if it matches one character and only that one. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 129 | 105 | ▶ | sub _ordinal { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_ordinal: called CC=6 SCAR=18.2
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 130 | 105 | my ($part) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 131 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 132 | 105 | ▶ | if ( $part->isa('PPIx::Regexp::Structure::CharClass') ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 133 | 4 | ▶ | return if $part->negated; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 134 | 4 | ▶ | $part = _sole_member($part) or return; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 135 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 136 | 103 | ▶ | return unless $part->isa('PPIx::Regexp::Token::Literal'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 137 | 85 | ▶ | return $part->ordinal // (); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
$part->ordinal // ()
MC/DC0%0/2
$part->ordinal // ()
$part->ordinal
()
Truth table33%1/3
A // B
A= $part->ordinalB= ()
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 138 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 139 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 140 | # The one member of the character class $class, if it has exactly one. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 141 | 45 | ▶ | sub _sole_member { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_sole_member: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 142 | 45 | my ($class) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 143 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 144 | 45 | my @members = $class->children; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 145 | 45 | ▶ | return unless @members == 1; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 146 | 42 | return $members[0]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 147 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 148 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 149 | # Whether @$body, the inside of the capture, takes everything up to the first | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 150 | # occurrence of the separator in @$ordinals. Either it is a run of anything but | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 151 | # the separator's one character, with any greediness, or it is a lazy run of | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 152 | # anything at all, which stops at the first occurrence of any separator. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 153 | 69 | ▶ | sub _is_everything_before { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_is_everything_before: called CC=12 SCAR=25.6
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 154 | 69 | my ( $body, $ordinals ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 155 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 156 | 69 | my ( $atom, $quantifier, $greediness, @rest ) = @$body; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 157 | 69 | ▶ | return if @rest; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 158 | 69 | ▶ | return unless $atom && $quantifier && $quantifier->isa('PPIx::Regexp::Token::Quantifier') && $QUANTIFIER{ $quantifier->content }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition77%7/9
$atom and $quantifier and $quantifier->isa("PPIx::Regexp::Token::Quantifier") and $QUANTIFIER{$quantifier->content}
$atom and $quantifier and $quantifier->isa("PPIx::Regexp::Token::Quantifier")
$atom and $quantifier
MC/DC50%2/4
$atom and $quantifier and $quantifier->isa("PPIx::Regexp::Token::Quantifier") and $QUANTIFIER{$quantifier->content}
$atom
$quantifier
$quantifier->isa("PPIx::Regexp::Token::Quantifier")
$QUANTIFIER{$quantifier->content}
Truth table60%3/5
A and B and C and D
A= $atomB= $quantifierC= $quantifier->isa("PPIx::Regexp::Token::Quantifier")D= $QUANTIFIER{$quantifier->content}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 159 | 66 | ▶ | return if $greediness && !$greediness->isa('PPIx::Regexp::Token::Greediness'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$greediness and not $greediness->isa("PPIx::Regexp::Token::Greediness")
MC/DC0%0/2
$greediness and not $greediness->isa("PPIx::Regexp::Token::Greediness")
$greediness
not $greediness->isa("PPIx::Regexp::Token::Greediness")
Truth table66%2/3
A and not(B)
A= $greedinessB= not $greediness->isa("PPIx::Regexp::Token::Greediness")
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 160 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 161 | 66 | my $excluded = _excluded_ordinal($atom); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 162 | 66 | ▶ | return @$ordinals == 1 && $ordinals->[0] == $excluded if defined $excluded; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
@$ordinals == 1 && $ordinals->[0] == $excluded
MC/DC100%2/2
@$ordinals == 1 && $ordinals->[0] == $excluded
@$ordinals == 1
$ordinals->[0] == $excluded
Truth table100%3/3
A && B
A= @$ordinals == 1B= $ordinals->[0] == $excluded
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 163 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 164 | 17 | ▶ | my $lazy = $greediness && $greediness->content eq '?'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
$greediness && $greediness->content eq '?'
MC/DC50%1/2
$greediness && $greediness->content eq '?'
$greediness
$greediness->content eq '?'
Truth table66%2/3
A && B
A= $greedinessB= $greediness->content eq '?'
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 165 | 17 | ▶ | return $lazy && _is_anything($atom); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
$lazy && _is_anything($atom)
MC/DC50%1/2
$lazy && _is_anything($atom)
$lazy
_is_anything($atom)
Truth table66%2/3
A && B
A= $lazyB= _is_anything($atom)
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 166 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 167 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 168 | # The one character $atom refuses, if it matches every character but one: a | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 169 | # negated class of one, \N, or a dot without /s. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 170 | 66 | ▶ | sub _excluded_ordinal { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_excluded_ordinal: called CC=9 SCAR=22.1
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 171 | 66 | my ($atom) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 172 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 173 | 66 | ▶ | if ( $atom->isa('PPIx::Regexp::Structure::CharClass') ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 174 | 41 | ▶ | return unless $atom->negated; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 175 | 41 | ▶ | my $member = _sole_member($atom) or return; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 176 | 40 | ▶ | return unless $member->isa('PPIx::Regexp::Token::Literal'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 177 | 40 | return $member->ordinal; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 178 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 179 | 25 | ▶ | return unless $atom->isa('PPIx::Regexp::Token::CharClass::Simple'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 180 | 25 | ▶ | return $NEWLINE if $atom->content eq '\N'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 181 | 22 | ▶ | return $NEWLINE if $atom->content eq '.' && !$atom->modifier_asserted('s'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$atom->content eq "." and not $atom->modifier_asserted("s")
MC/DC100%2/2
$atom->content eq "." and not $atom->modifier_asserted("s")
$atom->content eq "."
not $atom->modifier_asserted("s")
Truth table100%3/3
A and not(B)
A= $atom->content eq "."B= not $atom->modifier_asserted("s")
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 182 | 16 | return; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 183 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 184 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 185 | # Whether $atom matches every character: a dot under /s. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 186 | 11 | ▶ | sub _is_anything { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_is_anything: called CC=3 SCAR=14.2
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 187 | 11 | my ($atom) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 188 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 189 | 11 | ▶ | return $atom->isa('PPIx::Regexp::Token::CharClass::Simple') && $atom->content eq '.' && $atom->modifier_asserted('s'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition33%2/6
$atom->isa('PPIx::Regexp::Token::CharClass::Simple') && $atom->content eq '.' && $atom->modifier_asserted('s')
$atom->isa("PPIx::Regexp::Token::CharClass::Simple") and $atom->content eq "."
MC/DC0%0/3
$atom->isa('PPIx::Regexp::Token::CharClass::Simple') && $atom->content eq '.' && $atom->modifier_asserted('s')
$atom->isa("PPIx::Regexp::Token::CharClass::Simple")
$atom->content eq "."
$atom->modifier_asserted('s')
Truth table25%1/4
A and B && C
A= $atom->isa("PPIx::Regexp::Token::CharClass::Simple")B= $atom->content eq "."C= $atom->modifier_asserted('s')
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 190 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 191 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 192 | # The parts of a pattern that match something: whitespace and comments under | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 193 | # /x do not. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 194 | 142 | ▶ | sub _significant { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_significant: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 195 | 142 | my (@parts) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 196 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 197 | 142 | ▶ | return grep { !$_->isa('PPIx::Regexp::Token::Whitespace') && !$_->isa('PPIx::Regexp::Token::Comment') } @parts; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%3/3
$_->isa('PPIx::Regexp::Token::Whitespace') || $_->isa('PPIx::Regexp::Token::Comment')
MC/DC100%2/2
$_->isa('PPIx::Regexp::Token::Whitespace') || $_->isa('PPIx::Regexp::Token::Comment')
$_->isa('PPIx::Regexp::Token::Whitespace')
$_->isa('PPIx::Regexp::Token::Comment')
Truth table100%3/3
A || B
A= $_->isa('PPIx::Regexp::Token::Whitespace')B= $_->isa('PPIx::Regexp::Token::Comment')
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 198 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 199 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 200 | 2 | 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 201 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 202 | __END__ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||