blib/lib/Babble/Plugin/State.pm

filter: Statementstmt 13.3% 4 / 30 Branchbran 0.0% 0 / 8 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 16.6% 1 / 6 Podpod 0.0% 0 / 1 totaltotal 11.1% 5 / 45 CC 5 SCAR 22.9
CC
5
Cov
11%
__ANON__
20.0
__ANON__
6.0
transform_to_plain
2.0
CRAP 9.9
« blib/lib/App/sigfix.pm ↑ Summary blib/lib/Babble/Match.pm »
1 package Babble::Plugin::State;
2  
3 1 ▶use Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 sub transform_to_plain {
6 0 ▶ my ($self, $top) = @_;
Subroutine transform_to_plain: not called CC=1 SCAR=6.9
Pod undocumented
7 0 $top->remove_use_argument(feature => 'state');
8 0 ▶ my $make_tf = sub { my ($lead) = @_; sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
9 0 ▶ my ($m) = @_;
Subroutine __ANON__: not called CC=4 SCAR=30.0
10 0 my @states;
11 my @gensym;
12 $m->each_match_within(Assignment => [
13 'state \b (?>(?&PerlOWS))',
14 [ type => '(?: (?&PerlQualifiedIdentifier) (?&PerlOWS) )?+' ],
15 [ declares => '(?>(?&PerlLvalue))' ],
16 '(?>(?&PerlOWS))',
17 [ attributes => '(?&PerlAttributes)?+' ],
18 '(?: (?>(?&PerlOWS)) = (?>(?&PerlOWS))',
19 [ assigns => '(?&PerlConditionalExpression)' ],
20 ')*+',
21 ] => sub {
22 0 ▶ my ($m) = @_;
Subroutine __ANON__: not called CC=2 SCAR=17.9
23 0 my $st = $m->subtexts;
24 0 push @states, $st;
25 0 ▶ if (my $assigns = $st->{assigns}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $assigns = $st->{"assigns"}) 0 0 0
26 0 my $genlex = '$'.$m->gensym;
27 my $text = '('
28 .$genlex
29 .' ? '.$st->{declares}
30 0 .' : ++'.$genlex.' and '.$st->{declares}.' = '.$assigns
31 .')';
32 0 push @gensym, $genlex;
33 0 $m->replace_text($text);
34 0 return;
35 }
36 0 $m->replace_text('do { no warnings qw(void); '.$st->{declares}.' }');
37 0 });
38 0 ▶ if (@states) {
Branch: 1 branch
BranchTrueFalseTotal
if (@states) 0 0 0
39 my $state_statements = join ' ',
40 (@gensym ? 'my ('.join(', ', @gensym).');' : ()),
41 (map {
42 0 ▶ 'my '.$_->{type}.$_->{declares}
Branch: 1 branch
BranchTrueFalseTotal
@gensym ? : 0 0 0
43 0 ▶ .($_->{attributes} ? ' '.$_->{attributes} : '')
Branch: 1 branch
BranchTrueFalseTotal
$_->{'attributes'} ? : 0 0 0
44 .';'
45 } @states);
46 $m->transform_text(sub {
47 0 ▶ s/\A/${lead}{ ${state_statements} /;
Subroutine __ANON__: not called CC=1 SCAR=6.9
48 0 s/\Z/ }/;
49 0 });
50 }
51 0 } };
52 0 $top->each_match_of(AnonymousSubroutine => $make_tf->('do '));
53 0 $top->each_match_of(SubroutineDeclaration => $make_tf->(''));
54 }
55  
56 1 1;
« blib/lib/App/sigfix.pm ↑ Summary blib/lib/Babble/Match.pm »