File Coverage

blib/lib/PPIx/Regexp/Structure/Assertion.pm
Criterion Covered Total %
statement 35 37 94.5
branch 5 8 62.5
condition 8 12 66.6
subroutine 12 13 92.3
pod 4 4 100.0
total 64 74 86.4


line stmt bran cond sub pod time code
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 is a
14             L.
15              
16             C 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     9   80 use strict;
  9         20  
  9         278  
33 9     9   45 use warnings;
  9         18  
  9         275  
34              
35 9     9   50 use base qw{ PPIx::Regexp::Structure };
  9         15  
  9         837  
36              
37 9     9   67 use Carp qw{ confess };
  9         20  
  9         436  
38 9     9   71 use List::Util qw{ max };
  9         27  
  9         756  
39              
40             our $VERSION = '0.087';
41              
42 9         4365 use PPIx::Regexp::Constant qw{
43             LITERAL_LEFT_CURLY_ALLOWED
44             VARIABLE_LENGTH_LOOK_BEHIND_INTRODUCED
45             @CARP_NOT
46 9     9   74 };
  9         21  
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             sub is_look_ahead {
56 17     17 1 36 my ( $self ) = @_;
57 17         49 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             sub is_positive {
68 0     0 1 0 my ( $self ) = @_;
69 0         0 return $self->_get_type()->is_positive();
70             }
71              
72             sub perl_version_introduced {
73 13     13 1 27 my ( $self ) = @_;
74             return( $self->{perl_version_introduced} ||=
75 13   33     51 $self->_perl_version_introduced() );
76             }
77              
78             sub _perl_version_introduced {
79 13     13   24 my ( $self ) = @_;
80 13         47 my $ver = max( map { $_->perl_version_introduced() }
  29         96  
81             $self->children() );
82 13 100 100     62 if ( $ver < VARIABLE_LENGTH_LOOK_BEHIND_INTRODUCED &&
83             ! $self->is_look_ahead()
84             ) {
85 2         16 my ( $wid_min, $wid_max ) = $self->raw_width();
86 2 50 66     24 defined $wid_min
      66        
87             and defined $wid_max
88             and $wid_min < $wid_max
89             and $ver = max( $ver, VARIABLE_LENGTH_LOOK_BEHIND_INTRODUCED );
90             }
91 13         57 return $ver;
92             }
93              
94             sub width {
95 5     5 1 15 return ( 0, 0 );
96             }
97              
98             # An un-escaped literal left curly bracket can always follow this
99             # element.
100             sub __following_literal_left_curly_disallowed_in {
101 1     1   7 return LITERAL_LEFT_CURLY_ALLOWED;
102             }
103              
104             sub _get_type {
105 17     17   38 my ( $self ) = @_;
106 17 50       59 my $type = $self->type()
107             or confess 'Programming error - no type object';
108 17 50       70 $type->isa( 'PPIx::Regexp::Token::GroupType::Assertion' )
109             or confess 'Programming error - type object is ', ref $type,
110             ' not PPIx::Regexp::Token::GroupType::Assertion';
111 17         67 return $type;
112             }
113              
114             1;
115              
116             __END__