Regexp/Node/Range.pm

filter: Statementstmt 97.5% 40 / 41 Branchbran 71.4% 10 / 14 Conditioncond 66.6% 2 / 3 MC/DCmcdc 50.0% 1 / 2 Subroutinesub 100% 8 / 8 Podpod 100% 1 / 1 totaltotal 89.8% 62 / 69 CC 11 SCAR 13.1
CC
11
Cov
90%
__PPIX_LEXER__finalize
6.0
_range_ends_compatible
4.1
explain
3.1
CRAP 3.7
« Regexp/Token/GroupType.pm ↑ Summary Regexp/Token/CharClass/POSIX.pm »
1 =head1 NAME
2  
3 PPIx::Regexp::Node::Range - Represent a character range in a character class
4  
5 =head1 SYNOPSIS
6  
7 use PPIx::Regexp::Dumper;
8 PPIx::Regexp::Dumper->new( 'qr{[a-z]}smx' )
9 ->print();
10  
11 =head1 INHERITANCE
12  
13 C<PPIx::Regexp::Node::Range> is a
14 L<PPIx::Regexp::Node|PPIx::Regexp::Node>.
15  
16 C<PPIx::Regexp::Node::Range> has no descendants.
17  
18 =head1 DESCRIPTION
19  
20 This class represents a character range in a character class. It is a
21 node rather than a structure because there are no delimiters. The
22 content is simply the two literals with the '-' operator between them.
23  
24 =head1 METHODS
25  
26 This class provides no public methods beyond those provided by its
27 superclass.
28  
29 =cut
30  
31 package PPIx::Regexp::Node::Range;
32  
33 9 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
34 9 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
35  
36 9 ▶use base qw{ PPIx::Regexp::Node };
Subroutine BEGIN: called CC=1 SCAR=0.0
37  
38 9 ▶use PPIx::Regexp::Constant qw{
Subroutine BEGIN: called CC=1 SCAR=0.0
39 MSG_PROHIBITED_BY_STRICT
40 @CARP_NOT
41 9 };
42  
43 9 our $VERSION = '0.092';
44  
45 1 ▶sub explain {
Subroutine explain: called CC=3 SCAR=11.4
Pod documented
46 1 my ( $self ) = @_;
47 1 ▶ my $first = $self->schild( 0 )
Branch: 1 branch
BranchTrueFalseTotal
my $first = $self->schild(0) or return $self->__no_explanation 1 0 1
48 or return $self->__no_explanation();
49 1 ▶ my $last = $self->schild( -1 )
Branch: 1 branch
BranchTrueFalseTotal
my $last = $self->schild(-1) or return $self->__no_explanation 1 0 1
50 or return $self->__no_explanation();
51 1 return sprintf q<Characters between '%s' and '%s' inclusive>,
52 $first->content(), $last->content();
53 }
54  
55 13 ▶sub __PPIX_LEXER__finalize {
Subroutine __PPIX_LEXER__finalize: called CC=6 SCAR=18.0
56 13 my ( $self, $lexer ) = @_;
57  
58 13 my $rslt = $self->SUPER::__PPIX_LEXER__finalize( $lexer );
59  
60 13 ▶ if ( $lexer->strict() ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($lexer->strict) 3 10 13
61 # If strict is in effect, we're an error unless both ends of the
62 # range are portable.
63 3 my @kids = $self->schildren();
64 3 delete $self->{_range_start}; # Context for compatibility.
65 3 foreach my $inx ( 0, -1 ) {
66 6 my $kid = $kids[$inx];
67 # If we're not a literal, we can not make the test, so we
68 # blindly accept it.
69 6 ▶ $kid->isa( 'PPIx::Regexp::Token::Literal' )
Branch: 1 branch
BranchTrueFalseTotal
$kid->isa("PPIx::Regexp::Token::Literal") or next 6 0 6
70 or next;
71 6 my $content = $kid->content();
72 6 ▶ $content =~ m/ \A (?: [[:alnum:]] | \\N\{ .* \} ) \z /smx
Branch: 1 branch
BranchTrueFalseTotal
$content =~ / \A (?: [[:alnum:]] | \\N\{ .* \} ) \z /msx and $self->_range_ends_compatible($content) or return $self->_prohibited_by_strict($rslt) 4 2 6
Condition66%2/3
$content =~ / \A (?: [[:alnum:]] | \\N\{ .* \} ) \z /msx and $self->_range_ends_compatible($content)
!ll&&!rl&&r
024
MC/DC50%1/2
$content =~ / \A (?: [[:alnum:]] | \\N\{ .* \} ) \z /msx and $self->_range_ends_compatible($content)
$content =~ / \A (?: [[:alnum:]] | \\N\{ .* \} ) \z /msx $self->_range_ends_compatible($content)
Truth table66%2/3
A and B
A= $content =~ / \A (?: [[:alnum:]] | \\N\{ .* \} ) \z /msxB= $self->_range_ends_compatible($content)
ABresult
0X0
100
111
73 and $self->_range_ends_compatible( $content )
74 or return $self->_prohibited_by_strict( $rslt );
75 }
76 }
77  
78 11 return $rslt;
79 }
80  
81 2 ▶sub _prohibited_by_strict {
Subroutine _prohibited_by_strict: called CC=1 SCAR=0.0
82 2 my ( $self, $rslt ) = @_;
83 2 delete $self->{_range_start};
84 2 $rslt += $self->__error(
85 join( ' ', 'Non-portable range ends', MSG_PROHIBITED_BY_STRICT ),
86 perl_version_introduced => '5.023008',
87 );
88 2 return $rslt;
89 }
90  
91 6 ▶sub _range_ends_compatible {
Subroutine _range_ends_compatible: called CC=4 SCAR=14.0
92 6 my ( $self, $content ) = @_;
93 6 ▶ if ( defined( my $start = $self->{_range_start} ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $start = $self->{'_range_start'})) { } 3 3 6
94 3 foreach my $re (
95 qr{ \A [[:upper:]] \z }smx,
96 qr{ \A [[:lower:]] \z }smx,
97 qr{ \A [0-9] \z }smx,
98 qr{ \A \\N \{ .* \} }smx,
99 ) {
100 3 ▶ $start =~ $re
Branch: 1 branch
BranchTrueFalseTotal
$start =~ /$re/ or next 3 0 3
101 or next;
102 3 return $content =~ $re;
103 }
104 0 return;
105 } else {
106 3 $self->{_range_start} = $content;
107 3 return 1;
108 }
109 }
110  
111 9 1;
112  
113 __END__
« Regexp/Token/GroupType.pm ↑ Summary Regexp/Token/CharClass/POSIX.pm »