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<PPIx::Regexp::Token::GroupType::Assertion> is a
14             L<PPIx::Regexp::Token::GroupType|PPIx::Regexp::Token::GroupType>.
15              
16             C<PPIx::Regexp::Token::GroupType::Assertion> 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   69 use strict;
  9         19  
  9         287  
33 9     9   36 use warnings;
  9         14  
  9         418  
34              
35 9     9   38 use base qw{ PPIx::Regexp::Token::GroupType };
  9         13  
  9         4115  
36              
37 9         866 use PPIx::Regexp::Constant qw{
38             COOKIE_LOOKAROUND_ASSERTION
39             @CARP_NOT
40 9     9   43 };
  9         38  
41              
42             our $VERSION = '0.091';
43              
44 9     9   44 use constant EXPL_NLA => 'Negative look-ahead assertion';
  9         14  
  9         544  
45 9     9   39 use constant EXPL_NLB => 'Negative look-behind assertion';
  9         12  
  9         318  
46 9     9   35 use constant EXPL_PLA => 'Positive look-ahead assertion';
  9         9  
  9         321  
47 9     9   33 use constant EXPL_PLB => 'Positive look-behind assertion';
  9         24  
  9         1145  
48              
49 9         2437 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   51 };
  9         13  
110              
111             __PACKAGE__->__setup_class();
112              
113             sub __match_setup {
114 48     48   126 my ( undef, $tokenizer ) = @_; # $class not used
115 48 100       137 $tokenizer->__cookie_exists( COOKIE_LOOKAROUND_ASSERTION )
116             and return;
117 45         98 my $nest_depth = 1;
118             $tokenizer->cookie( COOKIE_LOOKAROUND_ASSERTION, sub {
119 233     233   333 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     1077 }->{ $token->content() } || 0 );
      66        
126 233         679 return $nest_depth;
127             },
128 45         307 );
129 45         78 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 26 my ( $self ) = @_;
141 17         69 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__
159              
160             =head1 SUPPORT
161              
162             Support is by the author. Please file bug reports at
163             L<https://rt.cpan.org/Public/Dist/Display.html?Name=PPIx-Regexp>,
164             L<https://github.com/trwyant/perl-PPIx-Regexp/issues>, or in
165             electronic mail to the author.
166              
167             =head1 AUTHOR
168              
169             Thomas R. Wyant, III F<wyant at cpan dot org>
170              
171             =head1 COPYRIGHT AND LICENSE
172              
173             Copyright (C) 2009-2023, 2025 by Thomas R. Wyant, III
174              
175             This program is free software; you can redistribute it and/or modify it
176             under the same terms as Perl 5.10.0. For more details, see the full text
177             of the licenses in the directory LICENSES.
178              
179             This program is distributed in the hope that it will be useful, but
180             without any warranty; without even the implied warranty of
181             merchantability or fitness for a particular purpose.
182              
183             =cut
184              
185             # ex: set textwidth=72 :