Regexp/Structure/Assertion.pm

filter: Statementstmt 94.8% 37 / 39 Branchbran 75.0% 6 / 8 Conditioncond 66.6% 8 / 12 MC/DCmcdc 42.8% 3 / 7 Subroutinesub 92.3% 12 / 13 Podpod 100% 4 / 4 totaltotal 84.3% 70 / 83 CC 9 SCAR 10.7
CC
9
Cov
86%
_perl_version_introduced
6.0
_get_type
3.1
perl_version_introduced
2.3
CRAP 2.9
« Regexp/Support.pm ↑ Summary Regexp/Token/Recursion.pm »
1 =head1 NAME
2  
3 PPIx::Regexp::Structure::Assertion - Represent a parenthesized assertion
4  
5 =head1 SYNOPSIS
6  
7 use PPIx::Regexp::Dumper;
8 PPIx::Regexp::Dumper->new( 'qr{(?<=foo)bar}smx' )
9 ->print();
10  
11 =head1 INHERITANCE
12  
13 C<PPIx::Regexp::Structure::Assertion> is a
14 L<PPIx::Regexp::Structure|PPIx::Regexp::Structure>.
15  
16 C<PPIx::Regexp::Structure::Assertion> has no descendants.
17  
18 =head1 DESCRIPTION
19  
20 This class represents one of the parenthesized assertions, either look
21 ahead or look behind, and either positive or negative.
22  
23 =head1 METHODS
24  
25 This class provides the following public methods beyond those provided
26 by its superclass.
27  
28 =cut
29  
30 package PPIx::Regexp::Structure::Assertion;
31  
32 9 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
33 9 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
34  
35 9 ▶use base qw{ PPIx::Regexp::Structure };
Subroutine BEGIN: called CC=1 SCAR=0.0
36  
37 9 ▶use Carp qw{ confess };
Subroutine BEGIN: called CC=1 SCAR=0.0
38 9 ▶use List::Util qw{ max };
Subroutine BEGIN: called CC=1 SCAR=0.0
39  
40 9 our $VERSION = '0.092';
41  
42 9 ▶use PPIx::Regexp::Constant qw{
Subroutine BEGIN: called CC=1 SCAR=0.0
43 LITERAL_LEFT_CURLY_ALLOWED
44 VARIABLE_LENGTH_LOOK_BEHIND_INTRODUCED
45 @CARP_NOT
46 9 };
47  
48 =head2 is_look_ahead
49  
50 This method returns a true value if the assertion is a look-ahead
51 assertion, or a false value if it is a look-behind assertion.
52  
53 =cut
54  
55 17 ▶sub is_look_ahead {
Subroutine is_look_ahead: called CC=1 SCAR=0.0
Pod documented
56 17 my ( $self ) = @_;
57 17 return $self->_get_type()->is_look_ahead();
58 }
59  
60 =head2 is_positive
61  
62 This method returns a true value if the assertion is a positive
63 assertion, or a false value if it is a negative assertion.
64  
65 =cut
66  
67 0 ▶sub is_positive {
Subroutine is_positive: not called CC=1 SCAR=6.9
Pod documented
68 0 my ( $self ) = @_;
69 0 return $self->_get_type()->is_positive();
70 }
71  
72 13 ▶sub perl_version_introduced {
Subroutine perl_version_introduced: called CC=2 SCAR=8.1
Pod documented
73 13 my ( $self ) = @_;
74 return( $self->{perl_version_introduced} ||=
75 13 ▶ $self->_perl_version_introduced() );
Condition33%1/3
$self->{"perl_version_introduced"} ||= $self->_perl_version_introduced
l!l&&r!l&&!r
0130
MC/DC0%0/2
$self->{"perl_version_introduced"} ||= $self->_perl_version_introduced
$self->{"perl_version_introduced"} $self->_perl_version_introduced
Truth table33%1/3
A ||= B
A= $self->{"perl_version_introduced"}B= $self->_perl_version_introduced
ABresult
1X1
011
000
76 }
77  
78 13 ▶sub _perl_version_introduced {
Subroutine _perl_version_introduced: called CC=6 SCAR=18.0
79 13 my ( $self ) = @_;
80 13 my $ver = max( map { $_->perl_version_introduced() }
81 $self->children() );
82 13 ▶ if ( $ver < VARIABLE_LENGTH_LOOK_BEHIND_INTRODUCED &&
Branch: 1 branch
BranchTrueFalseTotal
if ($ver < "5.029009" and not $self->is_look_ahead) 2 11 13
Condition100%3/3
$ver < "5.029009" and not $self->is_look_ahead
!ll&&!rl&&r
292
MC/DC100%2/2
$ver < "5.029009" and not $self->is_look_ahead
$ver < "5.029009" not $self->is_look_ahead
Truth table100%3/3
A and not(B)
A= $ver < "5.029009"B= not $self->is_look_ahead
ABresult
0X0
100
111
83 ! $self->is_look_ahead()
84 ) {
85 2 my ( $wid_min, $wid_max ) = $self->raw_width();
86 2 ▶ defined $wid_min
Branch: 1 branch
BranchTrueFalseTotal
defined $wid_min and defined $wid_max and $wid_min < $wid_max and $ver = &max($ver, "5.029009") 1 1 2
Condition66%4/6
defined $wid_min and defined $wid_max and $wid_min < $wid_max
!ll&&!rl&&r
101
defined $wid_min and defined $wid_max
!ll&&!rl&&r
101
MC/DC33%1/3
defined $wid_min and defined $wid_max and $wid_min < $wid_max
defined $wid_min defined $wid_max $wid_min < $wid_max
Truth table50%2/4
A and B and C
A= defined $wid_minB= defined $wid_maxC= $wid_min < $wid_max
ABCresult
0XX0
10X0
1100
1111
87 and defined $wid_max
88 and $wid_min < $wid_max
89 and $ver = max( $ver, VARIABLE_LENGTH_LOOK_BEHIND_INTRODUCED );
90 }
91 13 return $ver;
92 }
93  
94 5 ▶sub width {
Subroutine width: called CC=1 SCAR=0.0
Pod documented
95 5 return ( 0, 0 );
96 }
97  
98 # An un-escaped literal left curly bracket can always follow this
99 # element.
100 1 ▶sub __following_literal_left_curly_disallowed_in {
Subroutine __following_literal_left_curly_disallowed_in: called CC=1 SCAR=0.0
101 1 return LITERAL_LEFT_CURLY_ALLOWED;
102 }
103  
104 17 ▶sub _get_type {
Subroutine _get_type: called CC=3 SCAR=11.4
105 17 my ( $self ) = @_;
106 17 ▶ my $type = $self->type()
Branch: 1 branch
BranchTrueFalseTotal
my $type = $self->type or confess("Programming error - no type object") 17 0 17
107 or confess 'Programming error - no type object';
108 17 ▶ $type->isa( 'PPIx::Regexp::Token::GroupType::Assertion' )
Branch: 1 branch
BranchTrueFalseTotal
$type->isa("PPIx::Regexp::Token::GroupType::Assertion") or confess("Programming error - type object is ", ref $type, " not PPIx::Regexp::Token::GroupType::Assertion") 17 0 17
109 or confess 'Programming error - type object is ', ref $type,
110 ' not PPIx::Regexp::Token::GroupType::Assertion';
111 17 return $type;
112 }
113  
114 9 1;
115  
116 __END__
« Regexp/Support.pm ↑ Summary Regexp/Token/Recursion.pm »