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   74 use strict;
  9         31  
  9         276  
38 9     9   45 use warnings;
  9         18  
  9         243  
39              
40 9     9   48 use base qw{ PPIx::Regexp::Token::GroupType };
  9         20  
  9         709  
41              
42 9     9   55 use Carp qw{ confess };
  9         20  
  9         433  
43              
44 9     9   55 use PPIx::Regexp::Constant qw{ RE_CAPTURE_NAME @CARP_NOT };
  9         39  
  9         882  
45              
46             our $VERSION = '0.087';
47              
48 9     9   61 use constant TOKENIZER_ARGUMENT_REQUIRED => 1;
  9         19  
  9         2794  
49              
50             sub __new {
51 34     34   224 my ( $class, $content, %arg ) = @_;
52              
53             defined $arg{perl_version_introduced}
54 34 50       220 or $arg{perl_version_introduced} = '5.009005';
55              
56 34         220 my $self = $class->SUPER::__new( $content, %arg );
57              
58 34         275 foreach my $name ( $arg{tokenizer}->capture() ) {
59 34 50       169 defined $name or next;
60 34         140 $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 3 my ( $self ) = @_;
72 1         5 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 115 my ( $self ) = @_;
83 33         192 return $self->{name};
84             }
85              
86             sub __make_group_type_matcher {
87             return {
88 9     9   174 '' => [
89 6         570 qr/ \A [?] P? < ( @{[ RE_CAPTURE_NAME ]} ) > /smxo,
90 6         402 qr/ \A [?] ' ( @{[ RE_CAPTURE_NAME ]} ) ' /smxo,
91             ],
92             '?' => [
93 6         352 qr/ \A \\ [?] P? < ( @{[ RE_CAPTURE_NAME ]} ) > /smxo,
94 6         410 qr/ \A \\ [?] ' ( @{[ RE_CAPTURE_NAME ]} ) ' /smxo,
95             ],
96             q{'} => [
97 6         348 qr/ \A [?] P? < ( @{[ RE_CAPTURE_NAME ]} ) > /smxo,
98 6         386 qr/ \A [?] \\ ' ( @{[ RE_CAPTURE_NAME ]} ) \\ ' /smxo,
99             ],
100             };
101             }
102              
103             1;
104              
105             __END__