File Coverage

blib/lib/PPIx/Regexp/Token/GroupType/NamedCapture.pm
Criterion Covered Total %
statement 36 37 97.3
branch 2 4 50.0
condition n/a
subroutine 10 10 100.0
pod 2 2 100.0
total 50 53 94.3


line stmt bran cond sub pod time code
1             =head1 NAME
2              
3             PPIx::Regexp::Token::GroupType::NamedCapture - Represent a named capture
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 named capture specification. Its content will be
21             something like one of the following:
22              
23             ?
24             ?'NAME'
25             ?P
26              
27             =head1 METHODS
28              
29             This class provides the following public methods. Methods not documented
30             here are private, and unsupported in the sense that the author reserves
31             the right to change or remove them without notice.
32              
33             =cut
34              
35             package PPIx::Regexp::Token::GroupType::NamedCapture;
36              
37 9     9   58 use strict;
  9         21  
  9         256  
38 9     9   44 use warnings;
  9         18  
  9         307  
39              
40 9     9   48 use base qw{ PPIx::Regexp::Token::GroupType };
  9         25  
  9         720  
41              
42 9     9   64 use Carp qw{ confess };
  9         20  
  9         459  
43              
44 9     9   53 use PPIx::Regexp::Constant qw{ RE_CAPTURE_NAME @CARP_NOT };
  9         22  
  9         880  
45              
46             our $VERSION = '0.088';
47              
48 9     9   468 use constant TOKENIZER_ARGUMENT_REQUIRED => 1;
  9         19  
  9         3152  
49              
50             sub __new {
51 34     34   171 my ( $class, $content, %arg ) = @_;
52              
53             defined $arg{perl_version_introduced}
54 34 50       193 or $arg{perl_version_introduced} = '5.009005';
55              
56 34         184 my $self = $class->SUPER::__new( $content, %arg );
57              
58 34         190 foreach my $name ( $arg{tokenizer}->capture() ) {
59 34 50       128 defined $name or next;
60 34         131 $self->{name} = $name;
61 34         145 return $self;
62             }
63              
64 0         0 confess 'Programming error - can not figure out capture name';
65             }
66              
67             # Return true if the token can be quantified, and false otherwise
68             # sub can_be_quantified { return };
69              
70             sub explain {
71 1     1 1 4 my ( $self ) = @_;
72 1         3 return sprintf q, $self->name();
73             }
74              
75             =head2 name
76              
77             This method returns the name of the capture.
78              
79             =cut
80              
81             sub name {
82 33     33 1 100 my ( $self ) = @_;
83 33         173 return $self->{name};
84             }
85              
86             sub __make_group_type_matcher {
87             return {
88 9     9   91 '' => [
89 6         497 qr/ \A [?] P? < ( @{[ RE_CAPTURE_NAME ]} ) > /smxo,
90 6         373 qr/ \A [?] ' ( @{[ RE_CAPTURE_NAME ]} ) ' /smxo,
91             ],
92             '?' => [
93 6         354 qr/ \A \\ [?] P? < ( @{[ RE_CAPTURE_NAME ]} ) > /smxo,
94 6         333 qr/ \A \\ [?] ' ( @{[ RE_CAPTURE_NAME ]} ) ' /smxo,
95             ],
96             q{'} => [
97 6         350 qr/ \A [?] P? < ( @{[ RE_CAPTURE_NAME ]} ) > /smxo,
98 6         366 qr/ \A [?] \\ ' ( @{[ RE_CAPTURE_NAME ]} ) \\ ' /smxo,
99             ],
100             };
101             }
102              
103             1;
104              
105             __END__