File Coverage

blib/lib/PPIx/Regexp/Token/Greediness.pm
Criterion Covered Total %
statement 21 22 95.4
branch 4 4 100.0
condition 1 2 50.0
subroutine 8 9 88.8
pod 3 3 100.0
total 37 40 92.5


line stmt bran cond sub pod time code
1             =head1 NAME
2              
3             PPIx::Regexp::Token::Greediness - Represent a greediness qualifier.
4              
5             =head1 SYNOPSIS
6              
7             use PPIx::Regexp::Dumper;
8             PPIx::Regexp::Dumper->new( 'qr{foo*+}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 a greediness qualifier for the preceding
21             quantifier.
22              
23             =head1 METHODS
24              
25             This class provides the following public methods. Methods not documented
26             here are private, and unsupported in the sense that the author reserves
27             the right to change or remove them without notice.
28              
29             =cut
30              
31             package PPIx::Regexp::Token::Greediness;
32              
33 9     9   69 use strict;
  9         18  
  9         274  
34 9     9   47 use warnings;
  9         19  
  9         302  
35              
36 9     9   49 use base qw{ PPIx::Regexp::Token };
  9         19  
  9         899  
37              
38 9     9   61 use PPIx::Regexp::Constant qw{ MINIMUM_PERL @CARP_NOT };
  9         20  
  9         2633  
39              
40             our $VERSION = '0.088';
41              
42             # Return true if the token can be quantified, and false otherwise
43 0     0 1 0 sub can_be_quantified { return };
44              
45             {
46              
47             my %explanation = (
48             '+' => 'match longest string and give nothing back',
49             '?' => 'match shortest string first',
50             );
51              
52             sub __explanation {
53 2     2   10 return \%explanation;
54             }
55              
56             }
57              
58             my %greediness = (
59             '?' => MINIMUM_PERL,
60             '+' => '5.009005',
61             );
62              
63             =head2 could_be_greediness
64              
65             PPIx::Regexp::Token::Greediness->could_be_greediness( '?' );
66              
67             This method returns true if the given string could be a greediness
68             indicator; that is, if it is '+' or '?'.
69              
70             =cut
71              
72             sub could_be_greediness {
73 2     2 1 7 my ( undef, $string ) = @_; # Invocant unused
74 2         12 return $greediness{$string};
75             }
76              
77             sub perl_version_introduced {
78 4     4 1 686 my ( $self ) = @_;
79 4   50     23 return $greediness{ $self->content() } || MINIMUM_PERL;
80             }
81              
82             sub __PPIX_TOKENIZER__regexp {
83 1098     1098   2383 my ( undef, $tokenizer, $character ) = @_; # Invocant, $char_type unused
84              
85 1098 100       2605 $tokenizer->prior_significant_token( 'is_quantifier' )
86             or return;
87              
88 44 100       203 $greediness{$character} or return;
89              
90 15         54 return length $character;
91             }
92              
93             1;
94              
95             __END__