Babble/Plugin/PostfixDeref.pm

filter: Statementstmt 95.1% 39 / 41 Branchbran 100% 14 / 14 Conditioncond 33.3% 2 / 6 MC/DCmcdc 25.0% 1 / 4 Subroutinesub 83.3% 5 / 6 Podpod 0.0% 0 / 2 totaltotal 83.5% 61 / 73 CC 11 SCAR 18.3
CC
11
Cov
90%
__ANON__
9.0
check_bail_out_early
6.0
transform_to_plain
2.0
CRAP 6.3
« App/sigfix.pm ↑ Summary Babble/Config.pm »
1 package Babble::Plugin::PostfixDeref;
2  
3 1 ▶use Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use Babble::Config;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 1 my $term_derefable = q{
7 # Copied from <PerlTerm> rule in PPR::X@0.001002
8 # The remaining alternatives can all take postfix dereferencers...
9 # ...
10 (?:
11 (?= \$ ) (?&PerlScalarAccess)
12 |
13 (?= \@ ) (?&PerlArrayAccess)
14 |
15 (?= % ) (?&PerlHashAccess)
16 |
17 (?&PerlAnonymousSubroutine)
18 |
19 (?>(?&PerlNullaryBuiltinFunction)) (?! (?>(?&PerlOWS)) \( )
20 |
21 (?&PerlDoBlock) | (?&PerlEvalBlock)
22 |
23 (?&PerlCall)
24 |
25 (?&PerlVariableDeclaration)
26 |
27 (?&PerlTypeglob)
28 |
29 (?>(?&PerlParenthesesList))
30  
31 # Can optionally do a [...] lookup straight after the parens,
32 # followd by any number of other look-ups
33 (?:
34 (?>(?&PerlOWS)) (?&PerlArrayIndexer)
35 (?:
36 (?>(?&PerlOWS))
37 (?>
38 (?&PerlArrayIndexer)
39 | (?&PerlHashIndexer)
40 | (?&PerlParenthesesList)
41 )
42 )*+
43 )?+
44 |
45 (?&PerlAnonymousArray)
46 |
47 (?&PerlAnonymousHash)
48 |
49 (?&PerlDiamondOperator)
50 |
51 (?&PerlContextualMatch)
52 |
53 (?&PerlQuotelikeS)
54 |
55 (?&PerlQuotelikeTR)
56 |
57 (?&PerlQuotelikeQX)
58 |
59 (?&PerlLiteral)
60 )
61 };
62  
63 1 my $scalarnospace_post = q{
64 # Copied from <PerlScalarAccessNoSpace> rule in PPR::X@0.001002
65 # Then any nuber of arrowed accesses
66 # (this is an inlined subset of (?&PerlTermPostfixDereference))...
67 (?:
68 ->
69 (?>
70 # A series of simple brackets can omit interstitial arrows...
71 (?: (?&PerlArrayIndexer)
72 | (?&PerlHashIndexer)
73 )++
74  
75 | # An array or hash slice...
76 \@ (?> (?>(?&PerlArrayIndexer)) | (?>(?&PerlHashIndexer)) )
77 )
78 )*+
79  
80 # Followed by at most one of these terminal arrowed dereferences...
81 (?:
82 ->
83 (?>
84 # An array or scalar deref...
85 [\@\$] \*
86  
87 | # An array count deref...
88 \$ \# \*
89 )
90 )?+
91 };
92  
93 27 ▶sub transform_to_plain {
Subroutine transform_to_plain: called CC=2 SCAR=6.9
Pod undocumented
94 27 my ($self, $top) = @_;
95 27 for my $argument (qw(postderef postderef_qq)) {
96 54 $top->remove_use_argument(experimental => $argument);
97 54 $top->remove_use_argument(feature => $argument);
98 }
99 29 ▶ my $tf = sub {
Subroutine __ANON__: called CC=9 SCAR=22.0
100 29 my ($m, $in_quotelike) = @_;
101 29 ▶ return if Babble::Config::BAIL_OUT_LATE && $m->text !~ m/ \s* -> \s* [\@%\$\&\*] /xs;
Branch: 1 branch
BranchTrueFalseTotal
unless $m->text =~ / \s* -> \s* [\@%\$\&\*] /sx 6 23 29
102 23 ▶ my $interpolate = defined $in_quotelike && $in_quotelike;
Condition66%2/3
defined $in_quotelike && $in_quotelike
!ll&&!rl&&r
1805
MC/DC50%1/2
defined $in_quotelike && $in_quotelike
defined $in_quotelike $in_quotelike
Truth table66%2/3
A && B
A= defined $in_quotelikeB= $in_quotelike
ABresult
0X0
100
111
103 23 my ($term, $postfix) = $m->subtexts(qw(term postfix));
104 #warn "Term: $term"; warn "Postfix: $postfix";
105 23 my $grammar = $m->grammar_regexp;
106 23 my $strip_re = qr{
107 ( (?>(?&PerlOWS)) -> (?>(?&PerlOWS))
108 (?>
109 \$\#\*
110 | [\$\&\*]\*
111 | (?> (?&PerlQualifiedIdentifier) | (?&PerlVariableScalar) )
112 (?: (?>(?&PerlOWS)) (?&PerlParenthesesList) )?+
113 | (?:
114 (?>(?&PerlOWS))
115 (?> (?&PerlParenthesesList) | (?&PerlArrayIndexer) | (?&PerlHashIndexer) )
116 )++
117 )
118 )
119 ${grammar}
120 }x;
121 23 ▶ while ($postfix =~ s/^${strip_re}//) {
Branch: 1 branch
BranchTrueFalseTotal
if ($postfix =~ s/^$strip_re//) 14 23 37
122 14 my $stripped = $1;
123 14 ▶ if ($stripped =~ /(\$\#?|[\&\*])\*$/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($stripped =~ /(\$\#?|[\&\*])\*$/) { } 9 5 14
124 9 my $sigil = $1;
125 9 $term = $sigil.'{'.$term.'}';
126 9 ▶ if( $interpolate ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($interpolate) 2 7 9
127 2 $term = "\@{[ $term ]}";
128 }
129 } else {
130 5 $term .= $stripped;
131 }
132 }
133 23 ▶ if ($postfix) {
Branch: 1 branch
BranchTrueFalseTotal
if ($postfix) 14 9 23
134 14 my ($sigil, $rest) = ($postfix =~ /^\s*->\s*([\@%])(.*)$/);
135 14 ▶ $rest = '' if $rest eq '*';
Branch: 1 branch
BranchTrueFalseTotal
if $rest eq "*" 9 5 14
136 14 $term = $sigil.'{'.$term.'}'.$rest;
137 14 ▶ if( $interpolate ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($interpolate) 3 11 14
138 # NOTE This can be interpolated safely
139 # because:
140 # 1. The delimiters are balanced so use inside of
141 # `qq{ ... }` or `qq[ ... ]` is safe.
142 # 2. The contents of $term can only contain expressions that
143 # have `$` and `@` sigils, so any expression contained in
144 # $term which is used within `qq@ ... @` will not have the
145 # `@` sigil (same with the `qq$ ... $` and `$` sigil).
146 3 $term = "\@{[ $term ]}";
147 }
148 }
149 23 $m->submatches->{term}->replace_text($term);
150 23 $m->submatches->{postfix}->replace_text('');
151 27 };
152 27 $top->each_match_within(Term => [
153 [ term => "(?> $term_derefable )" ],
154 [ postfix => '(?&PerlTermPostfixDereference)' ],
155 ] => $tf);
156  
157 # NOTE ScalarAccessNoSpace is used within the
158 # ScalarAccessNoSpaceNoArrow rule, but any such
159 # matches here via that rule would be invalid input
160 # to begin with.
161 $top->each_match_within(ScalarAccessNoSpace => [
162 [ term => q{
163 (?>(?&PerlVariableScalarNoSpace))
164  
165 # Optional arrowless access(es) to begin...
166 (?: (?&PerlArrayIndexer) | (?&PerlHashIndexer) )*+
167 } ],
168 [ postfix => $scalarnospace_post ],
169 27 ▶ ] => sub { $tf->(shift, 1) });
Subroutine __ANON__: called CC=1 SCAR=0.0
170 # NOTE ArrayAccessNoSpace also needs to implemented.
171 }
172  
173 0 ▶sub check_bail_out_early {
Subroutine check_bail_out_early: not called CC=2 SCAR=17.9
Pod undocumented
174 0 my ($self, $top) = @_;
175 0 ▶ $top->text !~ m/postderef|postderef_qq/xs
Condition0%0/3
$top->text =~ /postderef|postderef_qq/sx || $top->text =~ / \s* -> \s* [\@%\$\&\*] /sx
l!l&&r!l&&!r
000
MC/DC0%0/2
$top->text =~ /postderef|postderef_qq/sx || $top->text =~ / \s* -> \s* [\@%\$\&\*] /sx
$top->text =~ /postderef|postderef_qq/sx $top->text =~ / \s* -> \s* [\@%\$\&\*] /sx
Truth table0%0/3
A || B
A= $top->text =~ /postderef|postderef_qq/sxB= $top->text =~ / \s* -> \s* [\@%\$\&\*] /sx
ABresult
1X1
011
000
176 && $top->text !~ m/ \s* -> \s* [\@%\$\&\*] /xs;
177 }
178  
179 1 1;
180 __END__
« App/sigfix.pm ↑ Summary Babble/Config.pm »