| 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{(?<baz>foo)}smx' ) | ||||||||||
| 9 | ->print(); | ||||||||||
| 10 | |||||||||||
| 11 | =head1 INHERITANCE | ||||||||||
| 12 | |||||||||||
| 13 | C<PPIx::Regexp::Token::GroupType::NamedCapture> is a | ||||||||||
| 14 | L<PPIx::Regexp::Token::GroupType|PPIx::Regexp::Token::GroupType>. | ||||||||||
| 15 | |||||||||||
| 16 | C<PPIx::Regexp::Token::GroupType::NamedCapture> 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 | ?<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::Token::GroupType::NamedCapture; | ||||||||||
| 36 | |||||||||||
| 37 | 9 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 38 | 9 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 39 | |||||||||||
| 40 | 9 | ▶ | use base qw{ PPIx::Regexp::Token::GroupType }; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 41 | |||||||||||
| 42 | 9 | ▶ | use Carp qw{ confess }; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 43 | |||||||||||
| 44 | 9 | ▶ | use PPIx::Regexp::Constant qw{ RE_CAPTURE_NAME @CARP_NOT }; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 45 | |||||||||||
| 46 | 9 | our $VERSION = '0.092'; | |||||||||
| 47 | |||||||||||
| 48 | 9 | ▶ | use constant TOKENIZER_ARGUMENT_REQUIRED => 1; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 49 | |||||||||||
| 50 | 34 | ▶ | sub __new { | ||||||||
|
Subroutine
__new: called CC=4 SCAR=14.5
| |||||||||||
| 51 | 34 | my ( $class, $content, %arg ) = @_; | |||||||||
| 52 | |||||||||||
| 53 | defined $arg{perl_version_introduced} | ||||||||||
| 54 | 34 | ▶ | or $arg{perl_version_introduced} = '5.009005'; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 55 | |||||||||||
| 56 | 34 | my $self = $class->SUPER::__new( $content, %arg ); | |||||||||
| 57 | |||||||||||
| 58 | 34 | foreach my $name ( $arg{tokenizer}->capture() ) { | |||||||||
| 59 | 34 | ▶ | defined $name or next; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 60 | 34 | $self->{name} = $name; | |||||||||
| 61 | 34 | return $self; | |||||||||
| 62 | } | ||||||||||
| 63 | |||||||||||
| 64 | 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 | 1 | ▶ | sub explain { | ||||||||
|
Subroutine
explain: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 71 | 1 | my ( $self ) = @_; | |||||||||
| 72 | 1 | return sprintf q<Capture match into '%s'>, $self->name(); | |||||||||
| 73 | } | ||||||||||
| 74 | |||||||||||
| 75 | =head2 name | ||||||||||
| 76 | |||||||||||
| 77 | This method returns the name of the capture. | ||||||||||
| 78 | |||||||||||
| 79 | =cut | ||||||||||
| 80 | |||||||||||
| 81 | 33 | ▶ | sub name { | ||||||||
|
Subroutine
name: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 82 | 33 | my ( $self ) = @_; | |||||||||
| 83 | 33 | return $self->{name}; | |||||||||
| 84 | } | ||||||||||
| 85 | |||||||||||
| 86 | 9 | ▶ | sub __make_group_type_matcher { | ||||||||
|
Subroutine
__make_group_type_matcher: called CC=1 SCAR=0.0
| |||||||||||
| 87 | return { | ||||||||||
| 88 | 9 | '' => [ | |||||||||
| 89 | 6 | qr/ \A [?] P? < ( @{[ RE_CAPTURE_NAME ]} ) > /smxo, | |||||||||
| 90 | 6 | qr/ \A [?] ' ( @{[ RE_CAPTURE_NAME ]} ) ' /smxo, | |||||||||
| 91 | ], | ||||||||||
| 92 | '?' => [ | ||||||||||
| 93 | 6 | qr/ \A \\ [?] P? < ( @{[ RE_CAPTURE_NAME ]} ) > /smxo, | |||||||||
| 94 | 6 | qr/ \A \\ [?] ' ( @{[ RE_CAPTURE_NAME ]} ) ' /smxo, | |||||||||
| 95 | ], | ||||||||||
| 96 | q{'} => [ | ||||||||||
| 97 | 6 | qr/ \A [?] P? < ( @{[ RE_CAPTURE_NAME ]} ) > /smxo, | |||||||||
| 98 | 6 | qr/ \A [?] \\ ' ( @{[ RE_CAPTURE_NAME ]} ) \\ ' /smxo, | |||||||||
| 99 | ], | ||||||||||
| 100 | }; | ||||||||||
| 101 | } | ||||||||||
| 102 | |||||||||||
| 103 | 9 | 1; | |||||||||
| 104 | |||||||||||
| 105 | __END__ | ||||||||||