| 1 | =head1 NAME | ||||||||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||||||||
| 3 | PPIx::Regexp::Structure - Represent a structure. | ||||||||||||||||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||||||||||||||||
| 5 | =head1 SYNOPSIS | ||||||||||||||||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||||||||||||||||
| 7 | use PPIx::Regexp::Dumper; | ||||||||||||||||||||||||||||||||||||||||||
| 8 | PPIx::Regexp::Dumper->new( 'qr{(foo)}' )->print(); | ||||||||||||||||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||||||||||||||||
| 10 | =head1 INHERITANCE | ||||||||||||||||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||||||||||||||||
| 12 | C<PPIx::Regexp::Structure> is a | ||||||||||||||||||||||||||||||||||||||||||
| 13 | L<PPIx::Regexp::Node|PPIx::Regexp::Node>. | ||||||||||||||||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||||||||||||||||
| 15 | C<PPIx::Regexp::Structure> is the parent of | ||||||||||||||||||||||||||||||||||||||||||
| 16 | L<PPIx::Regexp::Structure::Assertion|PPIx::Regexp::Structure::Assertion>, | ||||||||||||||||||||||||||||||||||||||||||
| 17 | L<PPIx::Regexp::Structure::BranchReset|PPIx::Regexp::Structure::BranchReset>, | ||||||||||||||||||||||||||||||||||||||||||
| 18 | L<PPIx::Regexp::Structure::Capture|PPIx::Regexp::Structure::Capture>, | ||||||||||||||||||||||||||||||||||||||||||
| 19 | L<PPIx::Regexp::Structure::CharClass|PPIx::Regexp::Structure::CharClass>, | ||||||||||||||||||||||||||||||||||||||||||
| 20 | L<PPIx::Regexp::Structure::Code|PPIx::Regexp::Structure::Code>, | ||||||||||||||||||||||||||||||||||||||||||
| 21 | L<PPIx::Regexp::Structure::Main|PPIx::Regexp::Structure::Main>, | ||||||||||||||||||||||||||||||||||||||||||
| 22 | L<PPIx::Regexp::Structure::Modifier|PPIx::Regexp::Structure::Modifier>, | ||||||||||||||||||||||||||||||||||||||||||
| 23 | L<PPIx::Regexp::Structure::Quantifier|PPIx::Regexp::Structure::Quantifier>, | ||||||||||||||||||||||||||||||||||||||||||
| 24 | L<PPIx::Regexp::Structure::Script_Run|PPIx::Regexp::Structure::Script_Run>, | ||||||||||||||||||||||||||||||||||||||||||
| 25 | L<PPIx::Regexp::Structure::Subexpression|PPIx::Regexp::Structure::Subexpression>, | ||||||||||||||||||||||||||||||||||||||||||
| 26 | L<PPIx::Regexp::Structure::Switch|PPIx::Regexp::Structure::Switch> and | ||||||||||||||||||||||||||||||||||||||||||
| 27 | L<PPIx::Regexp::Structure::Unknown|PPIx::Regexp::Structure::Unknown>. | ||||||||||||||||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||||||||||||||||
| 29 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||||||||||||||||
| 31 | This class represents a bracketed construction of some sort. The | ||||||||||||||||||||||||||||||||||||||||||
| 32 | brackets are considered part of the structure, but not inside it. So the | ||||||||||||||||||||||||||||||||||||||||||
| 33 | C<elements()> method returns the brackets if they are defined, but the | ||||||||||||||||||||||||||||||||||||||||||
| 34 | C<children()> method does not. | ||||||||||||||||||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||||||||||||||||
| 36 | =head1 METHODS | ||||||||||||||||||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||||||||||||||||
| 38 | This class provides the following public methods. Methods not documented | ||||||||||||||||||||||||||||||||||||||||||
| 39 | here are private, and unsupported in the sense that the author reserves | ||||||||||||||||||||||||||||||||||||||||||
| 40 | the right to change or remove them without notice. | ||||||||||||||||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||||||||||||||||
| 42 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||||||||||||||||
| 44 | package PPIx::Regexp::Structure; | ||||||||||||||||||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||||||||||||||||
| 46 | 9 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 47 | 9 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||||||||||||||||
| 49 | 9 | ▶ | use base qw{ PPIx::Regexp::Node }; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||||||||||||||||
| 51 | 9 | ▶ | use Carp qw{ confess }; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 52 | 9 | ▶ | use PPIx::Regexp::Constant qw{ | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 53 | ARRAY_REF | ||||||||||||||||||||||||||||||||||||||||||
| 54 | HASH_REF | ||||||||||||||||||||||||||||||||||||||||||
| 55 | STRUCTURE_UNKNOWN | ||||||||||||||||||||||||||||||||||||||||||
| 56 | @CARP_NOT | ||||||||||||||||||||||||||||||||||||||||||
| 57 | 9 | }; | |||||||||||||||||||||||||||||||||||||||||
| 58 | 9 | ▶ | use PPIx::Regexp::Util qw{ __instance }; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 59 | 9 | ▶ | use Scalar::Util qw{ refaddr }; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||||||||||||||||
| 61 | 9 | our $VERSION = '0.092'; | |||||||||||||||||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||||||||||||||||
| 63 | 9 | ▶ | use constant ELEMENT_UNKNOWN => STRUCTURE_UNKNOWN; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||||||||||||||||
| 65 | 620 | ▶ | sub __new { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__new: called CC=20 SCAR=30.0
| |||||||||||||||||||||||||||||||||||||||||||
| 66 | 620 | my ( $class, @args ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 67 | 620 | my %brkt; | |||||||||||||||||||||||||||||||||||||||||
| 68 | 620 | ▶ | if ( HASH_REF eq ref $args[0] ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 69 | 38 | %brkt = %{ shift @args }; | |||||||||||||||||||||||||||||||||||||||||
| 70 | 38 | foreach my $key ( qw{ start type finish } ) { | |||||||||||||||||||||||||||||||||||||||||
| 71 | ARRAY_REF eq ref $brkt{$key} | ||||||||||||||||||||||||||||||||||||||||||
| 72 | 114 | ▶ | or $brkt{$key} = [ $brkt{$key} ]; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 73 | } | ||||||||||||||||||||||||||||||||||||||||||
| 74 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 75 | 582 | ▶ | $brkt{finish} = [ @args ? pop @args : () ]; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 76 | 582 | ▶ | $brkt{start} = [ @args ? shift @args : () ]; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 77 | 582 | ▶ | while ( @args && ! $args[0]->significant() ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
@args and not $args[0]->significant
MC/DC100%2/2
@args and not $args[0]->significant
@args
not $args[0]->significant
Truth table100%3/3
A and not(B)
A= @argsB= not $args[0]->significant
| |||||||||||||||||||||||||||||||||||||||||||
| 78 | 29 | push @{ $brkt{start} }, shift @args; | |||||||||||||||||||||||||||||||||||||||||
| 79 | } | ||||||||||||||||||||||||||||||||||||||||||
| 80 | 582 | $brkt{type} = []; | |||||||||||||||||||||||||||||||||||||||||
| 81 | 582 | ▶ | if ( __instance( $args[0], 'PPIx::Regexp::Token::GroupType' ) ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 82 | 110 | push @{ $brkt{type} }, shift @args; | |||||||||||||||||||||||||||||||||||||||||
| 83 | 110 | ▶ | while ( @args && ! $args[0]->significant() ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
@args and not $args[0]->significant
MC/DC100%2/2
@args and not $args[0]->significant
@args
not $args[0]->significant
Truth table100%3/3
A and not(B)
A= @argsB= not $args[0]->significant
| |||||||||||||||||||||||||||||||||||||||||||
| 84 | 1 | push @{ $brkt{type} }, shift @args; | |||||||||||||||||||||||||||||||||||||||||
| 85 | } | ||||||||||||||||||||||||||||||||||||||||||
| 86 | } | ||||||||||||||||||||||||||||||||||||||||||
| 87 | } | ||||||||||||||||||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||||||||||||||||
| 89 | 620 | $class->_check_for_interpolated_match( \%brkt, \@args ); | |||||||||||||||||||||||||||||||||||||||||
| 90 | |||||||||||||||||||||||||||||||||||||||||||
| 91 | 620 | ▶ | my $self = $class->SUPER::__new( @args ) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 92 | or return; | ||||||||||||||||||||||||||||||||||||||||||
| 93 | |||||||||||||||||||||||||||||||||||||||||||
| 94 | 620 | ▶ | if ( __instance( $brkt{type}[0], 'PPIx::Regexp::Token::GroupType' ) ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 95 | 114 | ( my $reclass = ref $brkt{type}[0] ) =~ | |||||||||||||||||||||||||||||||||||||||||
| 96 | s/ Token::GroupType /Structure/smx; | ||||||||||||||||||||||||||||||||||||||||||
| 97 | 114 | ▶ | $reclass->can( 'start' ) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 98 | or confess "Programming error - $reclass not loaded"; | ||||||||||||||||||||||||||||||||||||||||||
| 99 | 114 | bless $self, $reclass; | |||||||||||||||||||||||||||||||||||||||||
| 100 | } | ||||||||||||||||||||||||||||||||||||||||||
| 101 | |||||||||||||||||||||||||||||||||||||||||||
| 102 | 620 | foreach my $key ( qw{ start type finish } ) { | |||||||||||||||||||||||||||||||||||||||||
| 103 | 1860 | $self->{$key} = []; | |||||||||||||||||||||||||||||||||||||||||
| 104 | 1860 | ▶ | ARRAY_REF eq ref $brkt{$key} | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 105 | or confess "Programming error - '$brkt{$key}' not an ARRAY"; | ||||||||||||||||||||||||||||||||||||||||||
| 106 | 1860 | foreach my $val ( @{ $brkt{$key} } ) { | |||||||||||||||||||||||||||||||||||||||||
| 107 | 1428 | ▶ | defined $val or next; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 108 | 1370 | ▶ | __instance( $val, 'PPIx::Regexp::Element' ) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 109 | or confess "Programming error - '$val' not a ", | ||||||||||||||||||||||||||||||||||||||||||
| 110 | "PPIx::Regexp::Element"; | ||||||||||||||||||||||||||||||||||||||||||
| 111 | 1370 | push @{ $self->{$key} }, $val; | |||||||||||||||||||||||||||||||||||||||||
| 112 | 1370 | $val->_parent( $self ); | |||||||||||||||||||||||||||||||||||||||||
| 113 | } | ||||||||||||||||||||||||||||||||||||||||||
| 114 | } | ||||||||||||||||||||||||||||||||||||||||||
| 115 | |||||||||||||||||||||||||||||||||||||||||||
| 116 | 620 | @{ $self->{finish} } | |||||||||||||||||||||||||||||||||||||||||
| 117 | 620 | ▶ | or $self->{error} = 'Missing end delimiter'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 118 | |||||||||||||||||||||||||||||||||||||||||||
| 119 | 620 | return $self; | |||||||||||||||||||||||||||||||||||||||||
| 120 | } | ||||||||||||||||||||||||||||||||||||||||||
| 121 | |||||||||||||||||||||||||||||||||||||||||||
| 122 | =head2 elements | ||||||||||||||||||||||||||||||||||||||||||
| 123 | |||||||||||||||||||||||||||||||||||||||||||
| 124 | This override returns all components of the structure, including those | ||||||||||||||||||||||||||||||||||||||||||
| 125 | that define it. | ||||||||||||||||||||||||||||||||||||||||||
| 126 | |||||||||||||||||||||||||||||||||||||||||||
| 127 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 128 | |||||||||||||||||||||||||||||||||||||||||||
| 129 | 2951 | ▶ | sub elements { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
elements: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 130 | 2951 | my ( $self ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 131 | |||||||||||||||||||||||||||||||||||||||||||
| 132 | 2951 | ▶ | if ( wantarray ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 133 | return ( | ||||||||||||||||||||||||||||||||||||||||||
| 134 | 2950 | @{ $self->{start} }, | |||||||||||||||||||||||||||||||||||||||||
| 135 | 2950 | @{ $self->{type} }, | |||||||||||||||||||||||||||||||||||||||||
| 136 | 2950 | @{ $self->{children} }, | |||||||||||||||||||||||||||||||||||||||||
| 137 | 2950 | @{ $self->{finish} }, | |||||||||||||||||||||||||||||||||||||||||
| 138 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 139 | } elsif ( defined wantarray ) { | ||||||||||||||||||||||||||||||||||||||||||
| 140 | 1 | my $size = scalar @{ $self->{start} }; | |||||||||||||||||||||||||||||||||||||||||
| 141 | 1 | $size += scalar @{ $self->{type} }; | |||||||||||||||||||||||||||||||||||||||||
| 142 | 1 | $size += scalar @{ $self->{children} }; | |||||||||||||||||||||||||||||||||||||||||
| 143 | 1 | $size += scalar @{ $self->{finish} }; | |||||||||||||||||||||||||||||||||||||||||
| 144 | 1 | return $size; | |||||||||||||||||||||||||||||||||||||||||
| 145 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 146 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||
| 147 | } | ||||||||||||||||||||||||||||||||||||||||||
| 148 | } | ||||||||||||||||||||||||||||||||||||||||||
| 149 | |||||||||||||||||||||||||||||||||||||||||||
| 150 | { | ||||||||||||||||||||||||||||||||||||||||||
| 151 | 9 | my %explanation = ( | |||||||||||||||||||||||||||||||||||||||||
| 152 | q<(> => 'Grouping', # ) | ||||||||||||||||||||||||||||||||||||||||||
| 153 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 154 | |||||||||||||||||||||||||||||||||||||||||||
| 155 | 1 | ▶ | sub explain { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
explain: called CC=4 SCAR=17.2
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 156 | 1 | my ( $self ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 157 | 1 | ▶ | if ( my $type = $self->type() ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 158 | 0 | return $type->explain(); | |||||||||||||||||||||||||||||||||||||||||
| 159 | } | ||||||||||||||||||||||||||||||||||||||||||
| 160 | 1 | ▶ | if ( my $start = $self->start() ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 161 | # The check for a left parenthesis before returning | ||||||||||||||||||||||||||||||||||||||||||
| 162 | # 'Grouping' is probably superflous, since it appears that | ||||||||||||||||||||||||||||||||||||||||||
| 163 | # this method is overridden in all other cases where we | ||||||||||||||||||||||||||||||||||||||||||
| 164 | # might get here (i.e. '[...]', '{...}'). But I'm paranoid. | ||||||||||||||||||||||||||||||||||||||||||
| 165 | 1 | ▶ | return $explanation{ $start->content() } || $start->explain(); | ||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
$explanation{$start->content} || $start->explain
MC/DC0%0/2
$explanation{$start->content} || $start->explain
$explanation{$start->content}
$start->explain
Truth table33%1/3
A || B
A= $explanation{$start->content}B= $start->explain
| |||||||||||||||||||||||||||||||||||||||||||
| 166 | } | ||||||||||||||||||||||||||||||||||||||||||
| 167 | 0 | return $self->__no_explanation(); | |||||||||||||||||||||||||||||||||||||||||
| 168 | } | ||||||||||||||||||||||||||||||||||||||||||
| 169 | } | ||||||||||||||||||||||||||||||||||||||||||
| 170 | |||||||||||||||||||||||||||||||||||||||||||
| 171 | =head2 finish | ||||||||||||||||||||||||||||||||||||||||||
| 172 | |||||||||||||||||||||||||||||||||||||||||||
| 173 | my $elem = $struct->finish(); | ||||||||||||||||||||||||||||||||||||||||||
| 174 | my @elem = $struct->finish(); | ||||||||||||||||||||||||||||||||||||||||||
| 175 | my $elem = $struct->finish( 0 ); | ||||||||||||||||||||||||||||||||||||||||||
| 176 | |||||||||||||||||||||||||||||||||||||||||||
| 177 | Returns the finishing structure element. This is included in the | ||||||||||||||||||||||||||||||||||||||||||
| 178 | C<elements> but not in the C<children>. | ||||||||||||||||||||||||||||||||||||||||||
| 179 | |||||||||||||||||||||||||||||||||||||||||||
| 180 | The finishing element is actually an array, though it should never have | ||||||||||||||||||||||||||||||||||||||||||
| 181 | more than one element. Calling C<finish> in list context gets you all | ||||||||||||||||||||||||||||||||||||||||||
| 182 | elements of the array. Calling it in scalar context gets you an element | ||||||||||||||||||||||||||||||||||||||||||
| 183 | of the array, defaulting to element 0 if no argument is passed. | ||||||||||||||||||||||||||||||||||||||||||
| 184 | |||||||||||||||||||||||||||||||||||||||||||
| 185 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 186 | |||||||||||||||||||||||||||||||||||||||||||
| 187 | 9 | ▶ | sub finish { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
finish: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 188 | 710 | my ( $self, $inx ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 189 | 710 | ▶ | wantarray and return @{ $self->{finish} }; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 190 | 517 | ▶ | return $self->{finish}[ defined $inx ? $inx : 0 ]; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 191 | } | ||||||||||||||||||||||||||||||||||||||||||
| 192 | |||||||||||||||||||||||||||||||||||||||||||
| 193 | 3 | ▶ | sub first_element { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
first_element: called CC=5 SCAR=28.8
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 194 | 3 | my ( $self ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 195 | |||||||||||||||||||||||||||||||||||||||||||
| 196 | 3 | ▶ | $self->{start}[0] and return $self->{start}[0]; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 197 | |||||||||||||||||||||||||||||||||||||||||||
| 198 | 0 | ▶ | $self->{type}[0] and return $self->{type}[0]; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 199 | |||||||||||||||||||||||||||||||||||||||||||
| 200 | 0 | ▶ | if ( my $elem = $self->SUPER::first_element() ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 201 | 0 | return $elem; | |||||||||||||||||||||||||||||||||||||||||
| 202 | } | ||||||||||||||||||||||||||||||||||||||||||
| 203 | |||||||||||||||||||||||||||||||||||||||||||
| 204 | 0 | ▶ | $self->{finish}[0] and return $self->{finish}[0]; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 205 | |||||||||||||||||||||||||||||||||||||||||||
| 206 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||
| 207 | } | ||||||||||||||||||||||||||||||||||||||||||
| 208 | |||||||||||||||||||||||||||||||||||||||||||
| 209 | 45 | ▶ | sub last_element { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
last_element: called CC=5 SCAR=28.8
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 210 | 45 | my ( $self ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 211 | |||||||||||||||||||||||||||||||||||||||||||
| 212 | 45 | ▶ | $self->{finish}[-1] and return $self->{finish}[-1]; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 213 | |||||||||||||||||||||||||||||||||||||||||||
| 214 | 0 | ▶ | if ( my $elem = $self->SUPER::last_element() ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 215 | 0 | return $elem; | |||||||||||||||||||||||||||||||||||||||||
| 216 | } | ||||||||||||||||||||||||||||||||||||||||||
| 217 | |||||||||||||||||||||||||||||||||||||||||||
| 218 | 0 | ▶ | $self->{type}[-1] and return $self->{type}[-1]; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 219 | |||||||||||||||||||||||||||||||||||||||||||
| 220 | 0 | ▶ | $self->{start}[-1] and return $self->{start}[-1]; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 221 | |||||||||||||||||||||||||||||||||||||||||||
| 222 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||
| 223 | } | ||||||||||||||||||||||||||||||||||||||||||
| 224 | |||||||||||||||||||||||||||||||||||||||||||
| 225 | 0 | ▶ | sub remove_insignificant { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
remove_insignificant: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 226 | 0 | my ( $self ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 227 | return $self->__new( | ||||||||||||||||||||||||||||||||||||||||||
| 228 | 0 | map { $_->remove_insignificant() } $self->elements() ); | |||||||||||||||||||||||||||||||||||||||||
| 229 | } | ||||||||||||||||||||||||||||||||||||||||||
| 230 | |||||||||||||||||||||||||||||||||||||||||||
| 231 | =head2 start | ||||||||||||||||||||||||||||||||||||||||||
| 232 | |||||||||||||||||||||||||||||||||||||||||||
| 233 | my $elem = $struct->start(); | ||||||||||||||||||||||||||||||||||||||||||
| 234 | my @elem = $struct->start(); | ||||||||||||||||||||||||||||||||||||||||||
| 235 | my $elem = $struct->start( 0 ); | ||||||||||||||||||||||||||||||||||||||||||
| 236 | |||||||||||||||||||||||||||||||||||||||||||
| 237 | Returns the starting structure element. This is included in the | ||||||||||||||||||||||||||||||||||||||||||
| 238 | C<elements> but not in the C<children>. | ||||||||||||||||||||||||||||||||||||||||||
| 239 | |||||||||||||||||||||||||||||||||||||||||||
| 240 | The starting element is actually an array. The first element (element 0) | ||||||||||||||||||||||||||||||||||||||||||
| 241 | is the actual starting delimiter. Subsequent elements, if any, are | ||||||||||||||||||||||||||||||||||||||||||
| 242 | insignificant elements (comments or white space) absorbed into the start | ||||||||||||||||||||||||||||||||||||||||||
| 243 | element for ease of parsing subsequent elements. | ||||||||||||||||||||||||||||||||||||||||||
| 244 | |||||||||||||||||||||||||||||||||||||||||||
| 245 | Calling C<start> in list context gets you all elements of the array. | ||||||||||||||||||||||||||||||||||||||||||
| 246 | Calling it in scalar context gets you an element of the array, | ||||||||||||||||||||||||||||||||||||||||||
| 247 | defaulting to element 0 if no argument is passed. | ||||||||||||||||||||||||||||||||||||||||||
| 248 | |||||||||||||||||||||||||||||||||||||||||||
| 249 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 250 | |||||||||||||||||||||||||||||||||||||||||||
| 251 | 739 | ▶ | sub start { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
start: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 252 | 739 | my ( $self, $inx ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 253 | 739 | ▶ | wantarray and return @{ $self->{start} }; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 254 | 517 | ▶ | return $self->{start}[ defined $inx ? $inx : 0 ]; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 255 | } | ||||||||||||||||||||||||||||||||||||||||||
| 256 | |||||||||||||||||||||||||||||||||||||||||||
| 257 | =head2 type | ||||||||||||||||||||||||||||||||||||||||||
| 258 | |||||||||||||||||||||||||||||||||||||||||||
| 259 | my $elem = $struct->type(); | ||||||||||||||||||||||||||||||||||||||||||
| 260 | my @elem = $struct->type(); | ||||||||||||||||||||||||||||||||||||||||||
| 261 | my $elem = $struct->type( 0 ); | ||||||||||||||||||||||||||||||||||||||||||
| 262 | |||||||||||||||||||||||||||||||||||||||||||
| 263 | Returns the group type if any. This will be the leading | ||||||||||||||||||||||||||||||||||||||||||
| 264 | L<PPIx::Regexp::Token::GroupType|PPIx::Regexp::Token::GroupType> | ||||||||||||||||||||||||||||||||||||||||||
| 265 | token if any. This is included in C<elements> but not in C<children>. | ||||||||||||||||||||||||||||||||||||||||||
| 266 | |||||||||||||||||||||||||||||||||||||||||||
| 267 | The type is actually an array. The first element (element 0) is the | ||||||||||||||||||||||||||||||||||||||||||
| 268 | actual type determiner. Subsequent elements, if any, are insignificant | ||||||||||||||||||||||||||||||||||||||||||
| 269 | elements (comments or white space) absorbed into the type element for | ||||||||||||||||||||||||||||||||||||||||||
| 270 | consistency with the way the start element is handled. | ||||||||||||||||||||||||||||||||||||||||||
| 271 | |||||||||||||||||||||||||||||||||||||||||||
| 272 | Calling C<type> in list context gets you all elements of the array. | ||||||||||||||||||||||||||||||||||||||||||
| 273 | Calling it in scalar context gets you an element of the array, | ||||||||||||||||||||||||||||||||||||||||||
| 274 | defaulting to element 0 if no argument is passed. | ||||||||||||||||||||||||||||||||||||||||||
| 275 | |||||||||||||||||||||||||||||||||||||||||||
| 276 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 277 | |||||||||||||||||||||||||||||||||||||||||||
| 278 | 389 | ▶ | sub type { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
type: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 279 | 389 | my ( $self, $inx ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 280 | 389 | ▶ | wantarray and return @{ $self->{type} }; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 281 | 193 | ▶ | return $self->{type}[ defined $inx ? $inx : 0 ]; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 282 | } | ||||||||||||||||||||||||||||||||||||||||||
| 283 | |||||||||||||||||||||||||||||||||||||||||||
| 284 | # Check for things like (?$foo:...) or (?$foo) | ||||||||||||||||||||||||||||||||||||||||||
| 285 | 620 | ▶ | sub _check_for_interpolated_match { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_check_for_interpolated_match: called CC=17 SCAR=30.8
| |||||||||||||||||||||||||||||||||||||||||||
| 286 | 620 | my ( undef, $brkt, $args ) = @_; # Invocant unused | |||||||||||||||||||||||||||||||||||||||||
| 287 | |||||||||||||||||||||||||||||||||||||||||||
| 288 | # Everything we are interested in begins with a literal '?' followed | ||||||||||||||||||||||||||||||||||||||||||
| 289 | # by an interpolation. | ||||||||||||||||||||||||||||||||||||||||||
| 290 | 620 | ▶ | __instance( $args->[0], 'PPIx::Regexp::Token::Unknown' ) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition83%5/6
__instance($args->[0], "PPIx::Regexp::Token::Unknown") and $args->[0]->content eq "?" and __instance($args->[1], "PPIx::Regexp::Token::Interpolation")
__instance($args->[0], "PPIx::Regexp::Token::Unknown") and $args->[0]->content eq "?"
MC/DC66%2/3
__instance($args->[0], "PPIx::Regexp::Token::Unknown") and $args->[0]->content eq "?" and __instance($args->[1], "PPIx::Regexp::Token::Interpolation")
__instance($args->[0], "PPIx::Regexp::Token::Unknown")
$args->[0]->content eq "?"
__instance($args->[1], "PPIx::Regexp::Token::Interpolation")
Truth table75%3/4
A and B and C
A= __instance($args->[0], "PPIx::Regexp::Token::Unknown")B= $args->[0]->content eq "?"C= __instance($args->[1], "PPIx::Regexp::Token::Interpolation")
| |||||||||||||||||||||||||||||||||||||||||||
| 291 | and $args->[0]->content() eq '?' | ||||||||||||||||||||||||||||||||||||||||||
| 292 | and __instance( $args->[1], 'PPIx::Regexp::Token::Interpolation' ) | ||||||||||||||||||||||||||||||||||||||||||
| 293 | or return; | ||||||||||||||||||||||||||||||||||||||||||
| 294 | |||||||||||||||||||||||||||||||||||||||||||
| 295 | 4 | my $hiwater = 2; # Record how far we got into the arguments for | |||||||||||||||||||||||||||||||||||||||||
| 296 | # subsequent use detecting things like | ||||||||||||||||||||||||||||||||||||||||||
| 297 | # (?$foo). | ||||||||||||||||||||||||||||||||||||||||||
| 298 | |||||||||||||||||||||||||||||||||||||||||||
| 299 | # If we have a literal ':' as the third argument: | ||||||||||||||||||||||||||||||||||||||||||
| 300 | # GroupType::Modifier, rebless the ':' so we know not to match | ||||||||||||||||||||||||||||||||||||||||||
| 301 | # against it, and splice all three tokens into the type. | ||||||||||||||||||||||||||||||||||||||||||
| 302 | 4 | ▶ | if ( __instance( $args->[2], 'PPIx::Regexp::Token::Literal' ) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
__instance($args->[2], "PPIx::Regexp::Token::Literal") and $args->[2]->content eq ":"
MC/DC100%2/2
__instance($args->[2], "PPIx::Regexp::Token::Literal") and $args->[2]->content eq ":"
__instance($args->[2], "PPIx::Regexp::Token::Literal")
$args->[2]->content eq ":"
Truth table100%3/3
A and B
A= __instance($args->[2], "PPIx::Regexp::Token::Literal")B= $args->[2]->content eq ":"
| |||||||||||||||||||||||||||||||||||||||||||
| 303 | && $args->[2]->content() eq ':' ) { | ||||||||||||||||||||||||||||||||||||||||||
| 304 | |||||||||||||||||||||||||||||||||||||||||||
| 305 | # Rebless the '?' as a GroupType::Modifier. | ||||||||||||||||||||||||||||||||||||||||||
| 306 | 1 | PPIx::Regexp::Token::GroupType::Modifier->__PPIX_ELEM__rebless( | |||||||||||||||||||||||||||||||||||||||||
| 307 | $args->[0] ); | ||||||||||||||||||||||||||||||||||||||||||
| 308 | |||||||||||||||||||||||||||||||||||||||||||
| 309 | # Rebless the ':' as a GroupType, just so it does not look like | ||||||||||||||||||||||||||||||||||||||||||
| 310 | # something to match against. | ||||||||||||||||||||||||||||||||||||||||||
| 311 | 1 | PPIx::Regexp::Token::GroupType->__PPIX_ELEM__rebless( | |||||||||||||||||||||||||||||||||||||||||
| 312 | $args->[2] ); | ||||||||||||||||||||||||||||||||||||||||||
| 313 | |||||||||||||||||||||||||||||||||||||||||||
| 314 | # Shove our three significant tokens into the type. | ||||||||||||||||||||||||||||||||||||||||||
| 315 | 1 | push @{ $brkt->{type} }, splice @{ $args }, 0, 3; | |||||||||||||||||||||||||||||||||||||||||
| 316 | |||||||||||||||||||||||||||||||||||||||||||
| 317 | # Stuff all the immediately-following insignificant tokens into | ||||||||||||||||||||||||||||||||||||||||||
| 318 | # the type as well. | ||||||||||||||||||||||||||||||||||||||||||
| 319 | 1 | ▶ | while ( @{ $args } && ! $args->[0]->significant() ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
@{$args;} and not $args->[0]->significant
MC/DC0%0/2
@{$args;} and not $args->[0]->significant
@{$args;}
not $args->[0]->significant
Truth table33%1/3
A and not(B)
A= @{$args;}B= not $args->[0]->significant
| |||||||||||||||||||||||||||||||||||||||||||
| 320 | 0 | push @{ $brkt->{type} }, shift @{ $args }; | |||||||||||||||||||||||||||||||||||||||||
| 321 | } | ||||||||||||||||||||||||||||||||||||||||||
| 322 | |||||||||||||||||||||||||||||||||||||||||||
| 323 | # Return to the caller, since we have done all the damage we | ||||||||||||||||||||||||||||||||||||||||||
| 324 | # can. | ||||||||||||||||||||||||||||||||||||||||||
| 325 | 1 | return; | |||||||||||||||||||||||||||||||||||||||||
| 326 | } | ||||||||||||||||||||||||||||||||||||||||||
| 327 | |||||||||||||||||||||||||||||||||||||||||||
| 328 | # If we have a literal '-' as the third argument, we might have | ||||||||||||||||||||||||||||||||||||||||||
| 329 | # something like (?$on-$off:$foo). | ||||||||||||||||||||||||||||||||||||||||||
| 330 | 3 | ▶ | if ( __instance( $args->[2], 'PPIx::Regexp::Token::Literal' ) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%4/6
__instance($args->[2], "PPIx::Regexp::Token::Literal") and $args->[2]->content eq "-" and __instance($args->[3], "PPIx::Regexp::Token::Interpolation")
__instance($args->[2], "PPIx::Regexp::Token::Literal") and $args->[2]->content eq "-"
MC/DC33%1/3
__instance($args->[2], "PPIx::Regexp::Token::Literal") and $args->[2]->content eq "-" and __instance($args->[3], "PPIx::Regexp::Token::Interpolation")
__instance($args->[2], "PPIx::Regexp::Token::Literal")
$args->[2]->content eq "-"
__instance($args->[3], "PPIx::Regexp::Token::Interpolation")
Truth table50%2/4
A and B and C
A= __instance($args->[2], "PPIx::Regexp::Token::Literal")B= $args->[2]->content eq "-"C= __instance($args->[3], "PPIx::Regexp::Token::Interpolation")
| |||||||||||||||||||||||||||||||||||||||||||
| 331 | && $args->[2]->content() eq '-' | ||||||||||||||||||||||||||||||||||||||||||
| 332 | && __instance( $args->[3], 'PPIx::Regexp::Token::Interpolation' ) | ||||||||||||||||||||||||||||||||||||||||||
| 333 | ) { | ||||||||||||||||||||||||||||||||||||||||||
| 334 | 2 | $hiwater = 4; | |||||||||||||||||||||||||||||||||||||||||
| 335 | |||||||||||||||||||||||||||||||||||||||||||
| 336 | 2 | ▶ | if ( __instance( $args->[4], 'PPIx::Regexp::Token::Literal' ) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
__instance($args->[4], "PPIx::Regexp::Token::Literal") and $args->[4]->content eq ":"
MC/DC50%1/2
__instance($args->[4], "PPIx::Regexp::Token::Literal") and $args->[4]->content eq ":"
__instance($args->[4], "PPIx::Regexp::Token::Literal")
$args->[4]->content eq ":"
Truth table66%2/3
A and B
A= __instance($args->[4], "PPIx::Regexp::Token::Literal")B= $args->[4]->content eq ":"
| |||||||||||||||||||||||||||||||||||||||||||
| 337 | && $args->[4]->content() eq ':' ) { | ||||||||||||||||||||||||||||||||||||||||||
| 338 | |||||||||||||||||||||||||||||||||||||||||||
| 339 | # Rebless the '?' as a GroupType::Modifier. | ||||||||||||||||||||||||||||||||||||||||||
| 340 | 1 | PPIx::Regexp::Token::GroupType::Modifier->__PPIX_ELEM__rebless( | |||||||||||||||||||||||||||||||||||||||||
| 341 | $args->[0] ); | ||||||||||||||||||||||||||||||||||||||||||
| 342 | |||||||||||||||||||||||||||||||||||||||||||
| 343 | # Rebless the '-' and ':' as GroupType, just so they do not | ||||||||||||||||||||||||||||||||||||||||||
| 344 | # look like something to match against. | ||||||||||||||||||||||||||||||||||||||||||
| 345 | 1 | PPIx::Regexp::Token::GroupType->__PPIX_ELEM__rebless( | |||||||||||||||||||||||||||||||||||||||||
| 346 | $args->[2] ); | ||||||||||||||||||||||||||||||||||||||||||
| 347 | 1 | PPIx::Regexp::Token::GroupType->__PPIX_ELEM__rebless( | |||||||||||||||||||||||||||||||||||||||||
| 348 | $args->[4] ); | ||||||||||||||||||||||||||||||||||||||||||
| 349 | |||||||||||||||||||||||||||||||||||||||||||
| 350 | # Shove our five significant tokens into the type. | ||||||||||||||||||||||||||||||||||||||||||
| 351 | 1 | push @{ $brkt->{type} }, splice @{ $args }, 0, 5; | |||||||||||||||||||||||||||||||||||||||||
| 352 | |||||||||||||||||||||||||||||||||||||||||||
| 353 | # Stuff all the immediately-following insignificant tokens | ||||||||||||||||||||||||||||||||||||||||||
| 354 | # into the type as well. | ||||||||||||||||||||||||||||||||||||||||||
| 355 | 1 | ▶ | while ( @{ $args } && ! $args->[0]->significant() ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
@{$args;} and not $args->[0]->significant
MC/DC0%0/2
@{$args;} and not $args->[0]->significant
@{$args;}
not $args->[0]->significant
Truth table33%1/3
A and not(B)
A= @{$args;}B= not $args->[0]->significant
| |||||||||||||||||||||||||||||||||||||||||||
| 356 | 0 | push @{ $brkt->{type} }, shift @{ $args }; | |||||||||||||||||||||||||||||||||||||||||
| 357 | } | ||||||||||||||||||||||||||||||||||||||||||
| 358 | |||||||||||||||||||||||||||||||||||||||||||
| 359 | # Return to the caller, since we have done all the damage we | ||||||||||||||||||||||||||||||||||||||||||
| 360 | # can. | ||||||||||||||||||||||||||||||||||||||||||
| 361 | 1 | return; | |||||||||||||||||||||||||||||||||||||||||
| 362 | } | ||||||||||||||||||||||||||||||||||||||||||
| 363 | } | ||||||||||||||||||||||||||||||||||||||||||
| 364 | |||||||||||||||||||||||||||||||||||||||||||
| 365 | # If the group contains _any_ significant tokens at this point, we | ||||||||||||||||||||||||||||||||||||||||||
| 366 | # do _not_ have something like (?$foo). | ||||||||||||||||||||||||||||||||||||||||||
| 367 | 2 | foreach my $inx ( $hiwater .. $#$args ) { | |||||||||||||||||||||||||||||||||||||||||
| 368 | 0 | ▶ | $args->[$inx]->significant() and return; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 369 | } | ||||||||||||||||||||||||||||||||||||||||||
| 370 | |||||||||||||||||||||||||||||||||||||||||||
| 371 | # Rebless the '?' as a GroupType::Modifier. | ||||||||||||||||||||||||||||||||||||||||||
| 372 | PPIx::Regexp::Token::GroupType::Modifier->__PPIX_ELEM__rebless( | ||||||||||||||||||||||||||||||||||||||||||
| 373 | 2 | $args->[0] ); | |||||||||||||||||||||||||||||||||||||||||
| 374 | |||||||||||||||||||||||||||||||||||||||||||
| 375 | # Shove all the contents of $args into type, using splice to leave | ||||||||||||||||||||||||||||||||||||||||||
| 376 | # @{ $args } empty after we do this. | ||||||||||||||||||||||||||||||||||||||||||
| 377 | 2 | push @{ $brkt->{type} }, splice @{ $args }; | |||||||||||||||||||||||||||||||||||||||||
| 378 | |||||||||||||||||||||||||||||||||||||||||||
| 379 | # We have done all the damage we can. | ||||||||||||||||||||||||||||||||||||||||||
| 380 | 2 | return; | |||||||||||||||||||||||||||||||||||||||||
| 381 | } | ||||||||||||||||||||||||||||||||||||||||||
| 382 | |||||||||||||||||||||||||||||||||||||||||||
| 383 | 9 | 1; | |||||||||||||||||||||||||||||||||||||||||
| 384 | |||||||||||||||||||||||||||||||||||||||||||
| 385 | __END__ | ||||||||||||||||||||||||||||||||||||||||||