File Coverage

blib/lib/PPIx/Regexp/Token/Recursion.pm
Criterion Covered Total %
statement 25 28 89.2
branch 5 8 62.5
condition n/a
subroutine 10 10 100.0
pod 4 4 100.0
total 44 50 88.0


line stmt bran cond sub pod time code
1             =head1 NAME
2              
3             PPIx::Regexp::Token::Recursion - Represent a recursion
4              
5             =head1 SYNOPSIS
6              
7             use PPIx::Regexp::Dumper;
8             PPIx::Regexp::Dumper->new( 'qr{(foo(?1)?)}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 recursion to a named or numbered capture.
21              
22             =head1 METHODS
23              
24             This class provides no public methods beyond those provided by its
25             superclass.
26              
27             =cut
28              
29             package PPIx::Regexp::Token::Recursion;
30              
31 9     9   64 use strict;
  9         21  
  9         260  
32 9     9   48 use warnings;
  9         29  
  9         245  
33              
34 9     9   47 use base qw{ PPIx::Regexp::Token::Reference };
  9         17  
  9         758  
35              
36 9     9   68 use Carp qw{ confess };
  9         25  
  9         483  
37 9     9   56 use PPIx::Regexp::Constant qw{ RE_CAPTURE_NAME @CARP_NOT };
  9         20  
  9         3794  
38              
39             our $VERSION = '0.088';
40              
41             # Return true if the token can be quantified, and false otherwise
42             # sub can_be_quantified { return };
43              
44             sub explain {
45 4     4 1 10 my ( $self ) = @_;
46 4 100       17 $self->is_named()
47             and return sprintf q,
48             $self->name();
49 3 50       12 if ( $self->is_relative() ) {
    100          
50 0         0 my $number = $self->number();
51 0 0       0 $number >= 0
52             and return sprintf
53             q,
54             PPIx::Regexp::Util::__to_ordinal_en( $self->number() ),
55             $self->absolute();
56 0         0 return sprintf
57             q,
58             PPIx::Regexp::Util::__to_ordinal_en( - $self->number() ),
59             $self->absolute();
60             } elsif ( my $number = $self->absolute() ) {
61 1         7 return sprintf q, $number;
62             } else {
63 2         7 return q;
64             }
65             }
66              
67             sub perl_version_introduced {
68 8     8 1 2004 return '5.009005';
69             }
70              
71             sub raw_width {
72 1     1 1 4 return ( undef, undef );
73             }
74              
75             sub width {
76 5     5 1 13 return ( undef, undef );
77             }
78              
79             # This must be implemented by tokens which do not recognize themselves.
80             # The return is a list of list references. Each list reference must
81             # contain a regular expression that recognizes the token, and optionally
82             # a reference to a hash to pass to make_token as the class-specific
83             # arguments. The regular expression MUST be anchored to the beginning of
84             # the string.
85             sub __PPIX_TOKEN__recognize {
86             return (
87 16     16   123 [ qr{ \A \( \? (?: ( [-+]? [0-9]+ )) \) }smx, { is_named => 0 } ],
88             [ qr{ \A \( \? (?: R) \) }smx,
89             { is_named => 0, capture => '0' } ],
90 9         833 [ qr{ \A \( \? (?: & | P> ) ( @{[ RE_CAPTURE_NAME ]} ) \) }smxo,
91             { is_named => 1 } ],
92             );
93             }
94              
95             1;
96              
97             __END__