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<PPIx::Regexp::Token::Greediness> is a
14             L<PPIx::Regexp::Token|PPIx::Regexp::Token>.
15              
16             C<PPIx::Regexp::Token::Greediness> 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   49 use strict;
  9         14  
  9         276  
34 9     9   31 use warnings;
  9         11  
  9         352  
35              
36 9     9   31 use base qw{ PPIx::Regexp::Token };
  9         14  
  9         605  
37              
38 9     9   62 use PPIx::Regexp::Constant qw{ MINIMUM_PERL @CARP_NOT };
  9         16  
  9         2126  
39              
40             our $VERSION = '0.091';
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   7 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 4 my ( undef, $string ) = @_; # Invocant unused
74 2         8 return $greediness{$string};
75             }
76              
77             sub perl_version_introduced {
78 4     4 1 539 my ( $self ) = @_;
79 4   50     21 return $greediness{ $self->content() } || MINIMUM_PERL;
80             }
81              
82             sub __PPIX_TOKENIZER__regexp {
83 1098     1098   1783 my ( undef, $tokenizer, $character ) = @_; # Invocant, $char_type unused
84              
85 1098 100       2124 $tokenizer->prior_significant_token( 'is_quantifier' )
86             or return;
87              
88 44 100       130 $greediness{$character} or return;
89              
90 15         33 return length $character;
91             }
92              
93             1;
94              
95             __END__
96              
97             =head1 SUPPORT
98              
99             Support is by the author. Please file bug reports at
100             L<https://rt.cpan.org/Public/Dist/Display.html?Name=PPIx-Regexp>,
101             L<https://github.com/trwyant/perl-PPIx-Regexp/issues>, or in
102             electronic mail to the author.
103              
104             =head1 AUTHOR
105              
106             Thomas R. Wyant, III F<wyant at cpan dot org>
107              
108             =head1 COPYRIGHT AND LICENSE
109              
110             Copyright (C) 2009-2023, 2025 by Thomas R. Wyant, III
111              
112             This program is free software; you can redistribute it and/or modify it
113             under the same terms as Perl 5.10.0. For more details, see the full text
114             of the licenses in the directory LICENSES.
115              
116             This program is distributed in the hope that it will be useful, but
117             without any warranty; without even the implied warranty of
118             merchantability or fitness for a particular purpose.
119              
120             =cut
121              
122             # ex: set textwidth=72 :