| 1 | =head1 NAME | ||||||||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||||||||
| 3 | PPIx::Regexp::Token::Reference - Represent a reference to a capture | ||||||||||||||||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||||||||||||||||
| 5 | =head1 SYNOPSIS | ||||||||||||||||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||||||||||||||||
| 7 | use PPIx::Regexp::Dumper; | ||||||||||||||||||||||||||||||||||||||||||
| 8 | PPIx::Regexp::Dumper->new( 'qr{\1}smx' ) | ||||||||||||||||||||||||||||||||||||||||||
| 9 | ->print(); | ||||||||||||||||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||||||||||||||||
| 11 | =head1 INHERITANCE | ||||||||||||||||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||||||||||||||||
| 13 | C<PPIx::Regexp::Token::Reference> is a | ||||||||||||||||||||||||||||||||||||||||||
| 14 | L<PPIx::Regexp::Token|PPIx::Regexp::Token>. | ||||||||||||||||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||||||||||||||||
| 16 | C<PPIx::Regexp::Token::Reference> is the parent of | ||||||||||||||||||||||||||||||||||||||||||
| 17 | L<PPIx::Regexp::Token::Backreference|PPIx::Regexp::Token::Backreference>, | ||||||||||||||||||||||||||||||||||||||||||
| 18 | L<PPIx::Regexp::Token::Condition|PPIx::Regexp::Token::Condition> and | ||||||||||||||||||||||||||||||||||||||||||
| 19 | L<PPIx::Regexp::Token::Recursion|PPIx::Regexp::Token::Recursion>. | ||||||||||||||||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||||||||||||||||
| 21 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||||||||||||||||
| 23 | This abstract class represents a reference to a capture buffer, either | ||||||||||||||||||||||||||||||||||||||||||
| 24 | numbered or named. It should never be instantiated, but it provides a | ||||||||||||||||||||||||||||||||||||||||||
| 25 | number of methods to its subclasses. | ||||||||||||||||||||||||||||||||||||||||||
| 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::Reference; | ||||||||||||||||||||||||||||||||||||||||||
| 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 }; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||||||||||||||||
| 42 | 9 | ▶ | use Carp qw{ confess }; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 43 | 9 | ▶ | use List::Util qw{ first }; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 44 | 9 | ▶ | use PPIx::Regexp::Constant qw{ @CARP_NOT }; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||||||||||||||||
| 46 | 9 | our $VERSION = '0.092'; | |||||||||||||||||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||||||||||||||||
| 48 | 113 | ▶ | sub __new { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__new: called CC=12 SCAR=24.9
| |||||||||||||||||||||||||||||||||||||||||||
| 49 | 113 | my ( $class, $content, %arg ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||||||||||||||||
| 51 | 113 | ▶ | if ( defined $arg{capture} ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 52 | } elsif ( defined $arg{tokenizer} ) { | ||||||||||||||||||||||||||||||||||||||||||
| 53 | 101 | ▶ | $arg{capture} = first { defined $_ } $arg{tokenizer}->capture(); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 54 | } | ||||||||||||||||||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||||||||||||||||
| 56 | 113 | ▶ | unless ( defined $arg{capture} ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 57 | 24 | foreach ( $class->__PPIX_TOKEN__recognize() ) { | |||||||||||||||||||||||||||||||||||||||||
| 58 | 49 | my ( $re, $a ) = @{ $_ }; | |||||||||||||||||||||||||||||||||||||||||
| 59 | 49 | ▶ | $content =~ $re or next; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 60 | 24 | @arg{ keys %{ $a } } = @{ $a }{ keys %{ $a } }; | |||||||||||||||||||||||||||||||||||||||||
| 61 | 24 | foreach my $inx ( 1 .. $#- ) { | |||||||||||||||||||||||||||||||||||||||||
| 62 | 34 | ▶ | defined $-[$inx] or next; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 63 | 21 | $arg{capture} = substr $content, $-[$inx], $+[$inx] - $-[$inx]; | |||||||||||||||||||||||||||||||||||||||||
| 64 | 21 | last; | |||||||||||||||||||||||||||||||||||||||||
| 65 | } | ||||||||||||||||||||||||||||||||||||||||||
| 66 | 24 | last; | |||||||||||||||||||||||||||||||||||||||||
| 67 | } | ||||||||||||||||||||||||||||||||||||||||||
| 68 | } | ||||||||||||||||||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||||||||||||||||
| 70 | defined $arg{capture} | ||||||||||||||||||||||||||||||||||||||||||
| 71 | 113 | ▶ | or confess q{Programming error - reference '}, | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 72 | $content, q{' of unknown form}; | ||||||||||||||||||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||||||||||||||||
| 74 | 113 | ▶ | my $self = $class->SUPER::__new( $content, %arg ) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 75 | or return; | ||||||||||||||||||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||||||||||||||||
| 77 | 113 | $self->{is_named} = $arg{is_named}; | |||||||||||||||||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||||||||||||||||
| 79 | 113 | my $capture = delete $arg{capture}; | |||||||||||||||||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||||||||||||||||
| 81 | 113 | ▶ | if ( $self->{is_named} ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 82 | 35 | $self->{absolute} = undef; | |||||||||||||||||||||||||||||||||||||||||
| 83 | 35 | $self->{is_relative} = undef; | |||||||||||||||||||||||||||||||||||||||||
| 84 | 35 | $self->{name} = $capture; | |||||||||||||||||||||||||||||||||||||||||
| 85 | } elsif ( $capture !~ m/ \A [-+] /smx ) { | ||||||||||||||||||||||||||||||||||||||||||
| 86 | 59 | $self->{absolute} = $self->{number} = $capture; | |||||||||||||||||||||||||||||||||||||||||
| 87 | 59 | $self->{is_relative} = undef; | |||||||||||||||||||||||||||||||||||||||||
| 88 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 89 | 19 | $self->{number} = $capture; | |||||||||||||||||||||||||||||||||||||||||
| 90 | 19 | $self->{is_relative} = 1; | |||||||||||||||||||||||||||||||||||||||||
| 91 | } | ||||||||||||||||||||||||||||||||||||||||||
| 92 | |||||||||||||||||||||||||||||||||||||||||||
| 93 | 113 | return $self; | |||||||||||||||||||||||||||||||||||||||||
| 94 | } | ||||||||||||||||||||||||||||||||||||||||||
| 95 | |||||||||||||||||||||||||||||||||||||||||||
| 96 | =head2 absolute | ||||||||||||||||||||||||||||||||||||||||||
| 97 | |||||||||||||||||||||||||||||||||||||||||||
| 98 | print "The absolute reference is ", $ref->absolute(), "\n"; | ||||||||||||||||||||||||||||||||||||||||||
| 99 | |||||||||||||||||||||||||||||||||||||||||||
| 100 | This method returns the absolute number of the capture buffer referred | ||||||||||||||||||||||||||||||||||||||||||
| 101 | to. This is the same as number() for unsigned numeric references. If the | ||||||||||||||||||||||||||||||||||||||||||
| 102 | reference is to a named buffer, C<undef> is returned. | ||||||||||||||||||||||||||||||||||||||||||
| 103 | |||||||||||||||||||||||||||||||||||||||||||
| 104 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 105 | |||||||||||||||||||||||||||||||||||||||||||
| 106 | 69 | ▶ | sub absolute { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
absolute: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 107 | 69 | my ( $self ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 108 | 69 | return $self->{absolute}; | |||||||||||||||||||||||||||||||||||||||||
| 109 | } | ||||||||||||||||||||||||||||||||||||||||||
| 110 | |||||||||||||||||||||||||||||||||||||||||||
| 111 | =head2 is_named | ||||||||||||||||||||||||||||||||||||||||||
| 112 | |||||||||||||||||||||||||||||||||||||||||||
| 113 | $ref->is_named and print "named reference\n"; | ||||||||||||||||||||||||||||||||||||||||||
| 114 | |||||||||||||||||||||||||||||||||||||||||||
| 115 | This method returns true if the reference is named rather than numbered. | ||||||||||||||||||||||||||||||||||||||||||
| 116 | |||||||||||||||||||||||||||||||||||||||||||
| 117 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 118 | |||||||||||||||||||||||||||||||||||||||||||
| 119 | 87 | ▶ | sub is_named { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
is_named: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 120 | 87 | my ( $self ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 121 | 87 | return $self->{is_named}; | |||||||||||||||||||||||||||||||||||||||||
| 122 | } | ||||||||||||||||||||||||||||||||||||||||||
| 123 | |||||||||||||||||||||||||||||||||||||||||||
| 124 | =head2 is_relative | ||||||||||||||||||||||||||||||||||||||||||
| 125 | |||||||||||||||||||||||||||||||||||||||||||
| 126 | $ref->is_relative() | ||||||||||||||||||||||||||||||||||||||||||
| 127 | and print "relative numbered reference\n"; | ||||||||||||||||||||||||||||||||||||||||||
| 128 | |||||||||||||||||||||||||||||||||||||||||||
| 129 | This method returns true if the reference is numbered and it is a | ||||||||||||||||||||||||||||||||||||||||||
| 130 | relative number (i.e. if it is signed). | ||||||||||||||||||||||||||||||||||||||||||
| 131 | |||||||||||||||||||||||||||||||||||||||||||
| 132 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 133 | |||||||||||||||||||||||||||||||||||||||||||
| 134 | 5 | ▶ | sub is_relative { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
is_relative: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 135 | 5 | my ( $self ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 136 | 5 | return $self->{is_relative}; | |||||||||||||||||||||||||||||||||||||||||
| 137 | } | ||||||||||||||||||||||||||||||||||||||||||
| 138 | |||||||||||||||||||||||||||||||||||||||||||
| 139 | =head2 is_matcher | ||||||||||||||||||||||||||||||||||||||||||
| 140 | |||||||||||||||||||||||||||||||||||||||||||
| 141 | This method returns a true value because, although we do not actually | ||||||||||||||||||||||||||||||||||||||||||
| 142 | perform an analysis on the referred-to entity, we presume it matches | ||||||||||||||||||||||||||||||||||||||||||
| 143 | something. | ||||||||||||||||||||||||||||||||||||||||||
| 144 | |||||||||||||||||||||||||||||||||||||||||||
| 145 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 146 | |||||||||||||||||||||||||||||||||||||||||||
| 147 | 0 | ▶ | sub is_matcher { return 1; } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
is_matcher: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 148 | |||||||||||||||||||||||||||||||||||||||||||
| 149 | =head2 name | ||||||||||||||||||||||||||||||||||||||||||
| 150 | |||||||||||||||||||||||||||||||||||||||||||
| 151 | print "The name is ", $ref->name(), "\n"; | ||||||||||||||||||||||||||||||||||||||||||
| 152 | |||||||||||||||||||||||||||||||||||||||||||
| 153 | This method returns the name of the capture buffer referred to. In the | ||||||||||||||||||||||||||||||||||||||||||
| 154 | case of a reference to a numbered capture (i.e. C<is_named> returns | ||||||||||||||||||||||||||||||||||||||||||
| 155 | false), this method returns C<undef>. | ||||||||||||||||||||||||||||||||||||||||||
| 156 | |||||||||||||||||||||||||||||||||||||||||||
| 157 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 158 | |||||||||||||||||||||||||||||||||||||||||||
| 159 | 39 | ▶ | sub name { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
name: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 160 | 39 | my ( $self ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 161 | 39 | return $self->{name}; | |||||||||||||||||||||||||||||||||||||||||
| 162 | } | ||||||||||||||||||||||||||||||||||||||||||
| 163 | |||||||||||||||||||||||||||||||||||||||||||
| 164 | =head2 number | ||||||||||||||||||||||||||||||||||||||||||
| 165 | |||||||||||||||||||||||||||||||||||||||||||
| 166 | print "The number is ", $ref->number(), "\n"; | ||||||||||||||||||||||||||||||||||||||||||
| 167 | |||||||||||||||||||||||||||||||||||||||||||
| 168 | This method returns the number of the capture buffer referred to. In the | ||||||||||||||||||||||||||||||||||||||||||
| 169 | case of a reference to a named capture (i.e. C<is_named> returns true), | ||||||||||||||||||||||||||||||||||||||||||
| 170 | this method returns C<undef>. | ||||||||||||||||||||||||||||||||||||||||||
| 171 | |||||||||||||||||||||||||||||||||||||||||||
| 172 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 173 | |||||||||||||||||||||||||||||||||||||||||||
| 174 | 22 | ▶ | sub number { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
number: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 175 | 22 | my ( $self ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 176 | 22 | return $self->{number}; | |||||||||||||||||||||||||||||||||||||||||
| 177 | } | ||||||||||||||||||||||||||||||||||||||||||
| 178 | |||||||||||||||||||||||||||||||||||||||||||
| 179 | # Called by the lexer to record the capture number. | ||||||||||||||||||||||||||||||||||||||||||
| 180 | 63 | ▶ | sub __PPIX_LEXER__record_capture_number { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__PPIX_LEXER__record_capture_number: called CC=5 SCAR=16.2
| |||||||||||||||||||||||||||||||||||||||||||
| 181 | 63 | my ( $self, $number ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 182 | 63 | ▶ | if ( ! exists $self->{absolute} && exists $self->{number} | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%4/6
not exists $self->{"absolute"} and exists $self->{"number"} and $self->{"number"} =~ / \A [-+] /msx
not exists $self->{"absolute"} and exists $self->{"number"}
MC/DC33%1/3
not exists $self->{"absolute"} and exists $self->{"number"} and $self->{"number"} =~ / \A [-+] /msx
not exists $self->{"absolute"}
exists $self->{"number"}
$self->{"number"} =~ / \A [-+] /msx
Truth table50%2/4
not(A) and B and C
A= not exists $self->{"absolute"}B= exists $self->{"number"}C= $self->{"number"} =~ / \A [-+] /msx
| |||||||||||||||||||||||||||||||||||||||||||
| 183 | && $self->{number} =~ m/ \A [-+] /smx ) { | ||||||||||||||||||||||||||||||||||||||||||
| 184 | |||||||||||||||||||||||||||||||||||||||||||
| 185 | 10 | my $delta = $self->{number}; | |||||||||||||||||||||||||||||||||||||||||
| 186 | 10 | ▶ | $delta > 0 and --$delta; # no -0 or +0. | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 187 | 10 | $self->{absolute} = $number + $delta; | |||||||||||||||||||||||||||||||||||||||||
| 188 | |||||||||||||||||||||||||||||||||||||||||||
| 189 | } | ||||||||||||||||||||||||||||||||||||||||||
| 190 | 63 | return $number; | |||||||||||||||||||||||||||||||||||||||||
| 191 | } | ||||||||||||||||||||||||||||||||||||||||||
| 192 | |||||||||||||||||||||||||||||||||||||||||||
| 193 | 9 | 1; | |||||||||||||||||||||||||||||||||||||||||
| 194 | |||||||||||||||||||||||||||||||||||||||||||
| 195 | __END__ | ||||||||||||||||||||||||||||||||||||||||||