Regexp/Token/Condition.pm

filter: Statementstmt 100% 40 / 40 Branchbran 100% 12 / 12 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 8 / 8 Podpod 100% 2 / 2 totaltotal 100% 62 / 62 CC 8 SCAR 10.5
CC
8
Cov
100%
explain
5.0
__PPIX_TOKENIZER__regexp
3.0
perl_version_introduced
2.0
CRAP 2.9
« Regexp/Token/Recursion.pm ↑ Summary Regexp/Structure/Modifier.pm »
1 =head1 NAME
2  
3 PPIx::Regexp::Token::Condition - Represent the condition of a switch
4  
5 =head1 SYNOPSIS
6  
7 use PPIx::Regexp::Dumper;
8 PPIx::Regexp::Dumper->new( 'qr{(?(1)foo|bar)}smx' )
9 ->print();
10  
11 =head1 INHERITANCE
12  
13 C<PPIx::Regexp::Token::Condition> is a
14 L<PPIx::Regexp::Token::Reference|PPIx::Regexp::Token::Reference>.
15  
16 C<PPIx::Regexp::Token::Condition> has no descendants.
17  
18 =head1 DESCRIPTION
19  
20 This class represents the condition portion of a switch or conditional
21 expression, provided that condition is reasonably represented as a
22 token.
23  
24 =head1 METHODS
25  
26 This class provides no public methods beyond those provided by its
27 superclass.
28  
29 =cut
30  
31 package PPIx::Regexp::Token::Condition;
32  
33 9 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
34 9 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
35  
36 9 ▶use base qw{ PPIx::Regexp::Token::Reference };
Subroutine BEGIN: called CC=1 SCAR=0.0
37  
38 9 ▶use PPIx::Regexp::Constant qw{ RE_CAPTURE_NAME @CARP_NOT };
Subroutine BEGIN: called CC=1 SCAR=0.0
39  
40 9 our $VERSION = '0.092';
41  
42 {
43  
44 9 my %explanation = (
45 '(DEFINE)' => 'Define a group to be recursed into',
46 '(R)' => 'True if recursing',
47 );
48  
49 6 ▶ sub explain {
Subroutine explain: called CC=5 SCAR=16.1
Pod documented
50 6 my ( $self ) = @_;
51 6 my $content = $self->content();
52 6 ▶ if ( defined( my $expl = $explanation{$content} ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $expl = $explanation{$content})) 2 4 6
53 2 return $expl;
54 }
55 4 ▶ if ( $content =~ m/ \A [(] R /smx ) { # )
Branch: 1 branch
BranchTrueFalseTotal
if ($content =~ / \A [(] R /msx) 2 2 4
56 2 ▶ $self->is_named()
Branch: 1 branch
BranchTrueFalseTotal
$self->is_named and return sprintf("True if recursing directly inside capture group '%s'", $self->name) 1 1 2
57 and return sprintf
58 q<True if recursing directly inside capture group '%s'>,
59 $self->name();
60 1 return sprintf
61 q<True if recursing directly inside capture group %d>,
62 $self->absolute();
63 }
64 $self->is_named()
65 2 ▶ and return sprintf
Branch: 1 branch
BranchTrueFalseTotal
$self->is_named and return sprintf("True if capture group '%s' matched", $self->name) 1 1 2
66 q<True if capture group '%s' matched>,
67 $self->name();
68 1 return sprintf
69 q<True if capture group %d matched>,
70 $self->absolute();
71 }
72  
73 }
74  
75 9 ▶sub perl_version_introduced {
Subroutine perl_version_introduced: called CC=2 SCAR=6.9
Pod documented
76 19 my ( $self ) = @_;
77 19 ▶ $self->content() =~ m/ \A [(] [0-9]+ [)] \z /smx
Branch: 1 branch
BranchTrueFalseTotal
$self->content =~ / \A [(] [0-9]+ [)] \z /msx and return "5.005" 6 13 19
78 and return '5.005';
79 13 return '5.009005';
80 }
81  
82 9 my @recognize = (
83 [ qr{ \A \( (?: ( [0-9]+ ) | R ( [0-9]+ ) ) \) }smx,
84 { is_named => 0 } ],
85 [ qr{ \A \( R \) }smx,
86 { is_named => 0, capture => '0' } ],
87 9 [ qr{ \A \( (?: < ( @{[ RE_CAPTURE_NAME ]} ) > |
88 9 ' ( @{[ RE_CAPTURE_NAME ]} ) ' |
89 9 R & ( @{[ RE_CAPTURE_NAME ]} ) ) \) }smxo,
90 { is_named => 1} ],
91 [ qr{ \A \( DEFINE \) }smx,
92 { is_named => 0, capture => '0' } ],
93 );
94  
95 # This must be implemented by tokens which do not recognize themselves.
96 # The return is a list of list references. Each list reference must
97 # contain a regular expression that recognizes the token, and optionally
98 # a reference to a hash to pass to make_token as the class-specific
99 # arguments. The regular expression MUST be anchored to the beginning of
100 # the string.
101 8 ▶sub __PPIX_TOKEN__recognize {
Subroutine __PPIX_TOKEN__recognize: called CC=1 SCAR=0.0
102 8 return @recognize;
103 }
104  
105 # Return true if the token can be quantified, and false otherwise
106 # sub can_be_quantified { return };
107  
108 32 ▶sub __PPIX_TOKENIZER__regexp {
Subroutine __PPIX_TOKENIZER__regexp: called CC=3 SCAR=11.0
109 32 my ( undef, $tokenizer ) = @_; # Invocant, $character unused
110  
111 32 foreach ( @recognize ) {
112 78 my ( $re, $arg ) = @{ $_ };
113 78 ▶ my $accept = $tokenizer->find_regexp( $re ) or next;
Branch: 1 branch
BranchTrueFalseTotal
my $accept = $tokenizer->find_regexp($re) or next 26 52 78
114 26 return $tokenizer->make_token( $accept, __PACKAGE__, $arg );
115 }
116  
117 6 return;
118 }
119  
120 9 1;
121  
122 __END__
« Regexp/Token/Recursion.pm ↑ Summary Regexp/Structure/Modifier.pm »