File Coverage

blib/lib/PPIx/Regexp/Token/GroupType/Assertion.pm
Criterion Covered Total %
statement 37 39 94.8
branch 4 4 100.0
condition 4 5 80.0
subroutine 12 13 92.3
pod 2 2 100.0
total 59 63 93.6


line stmt bran cond sub pod time code
1             =head1 NAME
2              
3             PPIx::Regexp::Token::GroupType::Assertion - Represent a look ahead or look behind 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 is a
14             L.
15              
16             C has no descendants.
17              
18             =head1 DESCRIPTION
19              
20             This class represents the parenthesized look ahead and look behind
21             assertions.
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::Token::GroupType::Assertion;
31              
32 9     9   81 use strict;
  9         23  
  9         295  
33 9     9   53 use warnings;
  9         17  
  9         252  
34              
35 9     9   56 use base qw{ PPIx::Regexp::Token::GroupType };
  9         26  
  9         4162  
36              
37 9         909 use PPIx::Regexp::Constant qw{
38             COOKIE_LOOKAROUND_ASSERTION
39             @CARP_NOT
40 9     9   66 };
  9         20  
41              
42             our $VERSION = '0.087';
43              
44 9     9   62 use constant EXPL_NLA => 'Negative look-ahead assertion';
  9         20  
  9         492  
45 9     9   69 use constant EXPL_NLB => 'Negative look-behind assertion';
  9         19  
  9         438  
46 9     9   64 use constant EXPL_PLA => 'Positive look-ahead assertion';
  9         24  
  9         396  
47 9     9   50 use constant EXPL_PLB => 'Positive look-behind assertion';
  9         28  
  9         1473  
48              
49 9         2164 use constant DEF => {
50              
51             '?!' => {
52             expl => EXPL_NLA,
53             look_ahead => 1,
54             },
55             '*nla:' => {
56             expl => EXPL_NLA,
57             intro => '5.027009',
58             look_ahead => 1,
59             },
60             '*negative_lookahead:' => {
61             expl => EXPL_NLA,
62             intro => '5.027009',
63             look_ahead => 1,
64             },
65             '? {
66             expl => EXPL_NLB,
67             intro => '5.005',
68             },
69             '*nlb:' => {
70             expl => EXPL_NLB,
71             intro => '5.027009',
72             },
73             '*negative_lookbehind:' => {
74             expl => EXPL_NLB,
75             intro => '5.027009',
76             },
77             '?=' => {
78             expl => EXPL_PLA,
79             look_ahead => 1,
80             positive => 1,
81             },
82             '*pla:' => {
83             expl => EXPL_PLA,
84             intro => '5.027009',
85             look_ahead => 1,
86             positive => 1,
87             },
88             '*positive_lookahead:' => {
89             expl => EXPL_PLA,
90             intro => '5.027009',
91             look_ahead => 1,
92             positive => 1,
93             },
94             '?<=' => {
95             expl => EXPL_PLB,
96             intro => '5.005',
97             positive => 1,
98             },
99             '*plb:' => {
100             expl => EXPL_PLB,
101             intro => '5.027009',
102             positive => 1,
103             },
104             '*positive_lookbehind:' => {
105             expl => EXPL_PLB,
106             intro => '5.027009',
107             positive => 1,
108             },
109 9     9   60 };
  9         21  
110              
111             __PACKAGE__->__setup_class();
112              
113             sub __match_setup {
114 48     48   179 my ( undef, $tokenizer ) = @_; # $class not used
115 48 100       218 $tokenizer->__cookie_exists( COOKIE_LOOKAROUND_ASSERTION )
116             and return;
117 45         120 my $nest_depth = 1;
118             $tokenizer->cookie( COOKIE_LOOKAROUND_ASSERTION, sub {
119 233     233   559 my ( undef, $token ) = @_; # $tokenizer not used
120             $token
121             and $token->isa( 'PPIx::Regexp::Token::Structure' )
122             and $nest_depth += ( {
123             '(' => 1,
124             ')' => -1,
125 233 100 100     1612 }->{ $token->content() } || 0 );
      66        
126 233         982 return $nest_depth;
127             },
128 45         364 );
129 45         141 return;
130             }
131              
132             =head2 is_look_ahead
133              
134             This method returns a true value if the assertion is a look-ahead
135             assertion, or a false value if it is a look-behind assertion.
136              
137             =cut
138              
139             sub is_look_ahead {
140 17     17 1 38 my ( $self ) = @_;
141 17         75 return $self->DEF->{ $self->unescaped_content() }->{look_ahead};
142             }
143              
144             =head2 is_positive
145              
146             This method returns a true value if the assertion is a positive
147             assertion, or a false value if it is a negative assertion.
148              
149             =cut
150              
151             sub is_positive {
152 0     0 1   my ( $self ) = @_;
153 0           return $self->DEF->{ $self->unescaped_content() }->{positive};
154             }
155              
156             1;
157              
158             __END__