File Coverage

blib/lib/PPIx/Regexp/Structure/NamedCapture.pm
Criterion Covered Total %
statement 20 20 100.0
branch 1 2 50.0
condition n/a
subroutine 7 7 100.0
pod 2 2 100.0
total 30 31 96.7


line stmt bran cond sub pod time code
1             =head1 NAME
2              
3             PPIx::Regexp::Structure::NamedCapture - Represent a named capture
4              
5             =head1 SYNOPSIS
6              
7             use PPIx::Regexp::Dumper;
8             PPIx::Regexp::Dumper->new( 'qr{(?<foo>foo)}smx' )
9             ->print();
10              
11             =head1 INHERITANCE
12              
13             C<PPIx::Regexp::Structure::NamedCapture> is a
14             L<PPIx::Regexp::Structure::Capture|PPIx::Regexp::Structure::Capture>.
15              
16             C<PPIx::Regexp::Structure::NamedCapture> has no descendants.
17              
18             =head1 DESCRIPTION
19              
20             This class represents a named capture. Its content will be something
21             like one of the following:
22              
23             (?<NAME> ... )
24             (?'NAME' ... )
25             (?P<NAME> ... )
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::Structure::NamedCapture;
36              
37 9     9   45 use strict;
  9         13  
  9         254  
38 9     9   52 use warnings;
  9         12  
  9         380  
39              
40 9     9   41 use Carp;
  9         14  
  9         529  
41              
42 9     9   74 use base qw{ PPIx::Regexp::Structure::Capture };
  9         14  
  9         805  
43              
44 9     9   50 use PPIx::Regexp::Constant qw{ @CARP_NOT };
  9         33  
  9         1599  
45              
46             our $VERSION = '0.091';
47              
48             sub explain {
49 1     1 1 4 my ( $self ) = @_;
50 1         3 return sprintf q<Named capture group '%s' (number %d)>,
51             $self->name(), $self->number();
52             }
53              
54             =head2 name
55              
56             my $name = $element->name();
57              
58             This method returns the name of the capture.
59              
60             =cut
61              
62             sub name {
63 29     29 1 50 my ( $self ) = @_;
64 29 50       96 my $type = $self->type()
65             or croak 'Programming error - ', __PACKAGE__, ' without type object';
66 29         102 return $type->name();
67             }
68              
69             1;
70              
71             __END__
72              
73             =head1 SUPPORT
74              
75             Support is by the author. Please file bug reports at
76             L<https://rt.cpan.org/Public/Dist/Display.html?Name=PPIx-Regexp>,
77             L<https://github.com/trwyant/perl-PPIx-Regexp/issues>, or in
78             electronic mail to the author.
79              
80             =head1 AUTHOR
81              
82             Thomas R. Wyant, III F<wyant at cpan dot org>
83              
84             =head1 COPYRIGHT AND LICENSE
85              
86             Copyright (C) 2009-2023, 2025 by Thomas R. Wyant, III
87              
88             This program is free software; you can redistribute it and/or modify it
89             under the same terms as Perl 5.10.0. For more details, see the full text
90             of the licenses in the directory LICENSES.
91              
92             This program is distributed in the hope that it will be useful, but
93             without any warranty; without even the implied warranty of
94             merchantability or fitness for a particular purpose.
95              
96             =cut
97              
98             # ex: set textwidth=72 :