Babble/Plugin/State.pm

filter: Statementstmt 93.7% 30 / 32 Branchbran 87.5% 7 / 8 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 85.7% 6 / 7 Podpod 0.0% 0 / 2 totaltotal 87.7% 43 / 49 CC 5 SCAR 8.6
CC
5
Cov
92%
__ANON__
4.0
__ANON__
2.0
check_bail_out_early
2.0
CRAP 2.4
« Babble/Plugin/DefinedOr.pm ↑ Summary Babble.pm »
1 package Babble::Plugin::State;
2  
3 1 ▶use Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 6 ▶sub transform_to_plain {
Subroutine transform_to_plain: called CC=1 SCAR=0.0
Pod undocumented
6 6 my ($self, $top) = @_;
7 6 $top->remove_use_argument(feature => 'state');
8 12 ▶ my $make_tf = sub { my ($lead) = @_; sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
Subroutine __ANON__: called CC=4 SCAR=13.9
9 6 my ($m) = @_;
10 6 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 6 ▶ ] => sub {
Subroutine __ANON__: called CC=2 SCAR=6.9
22 6 my ($m) = @_;
23 6 my $st = $m->subtexts;
24 6 push @states, $st;
25 6 ▶ if (my $assigns = $st->{assigns}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $assigns = $st->{"assigns"}) 2 4 6
26 2 my $genlex = '$'.$m->gensym;
27 my $text = '('
28 .$genlex
29 .' ? '.$st->{declares}
30 2 .' : ++'.$genlex.' and '.$st->{declares}.' = '.$assigns
31 .')';
32 2 push @gensym, $genlex;
33 2 $m->replace_text($text);
34 2 return;
35 }
36 4 $m->replace_text('do { no warnings qw(void); '.$st->{declares}.' }');
37 6 });
38 6 ▶ if (@states) {
Branch: 1 branch
BranchTrueFalseTotal
if (@states) 6 0 6
39 my $state_statements = join ' ',
40 (@gensym ? 'my ('.join(', ', @gensym).');' : ()),
41 (map {
42 6 ▶ 'my '.$_->{type}.$_->{declares}
Branch: 1 branch
BranchTrueFalseTotal
@gensym ? : 2 4 6
43 6 ▶ .($_->{attributes} ? ' '.$_->{attributes} : '')
Branch: 1 branch
BranchTrueFalseTotal
$_->{'attributes'} ? : 2 4 6
44 .';'
45 } @states);
46 6 ▶ $m->transform_text(sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
47 6 s/\A/${lead}{ ${state_statements} /;
48 6 s/\Z/ }/;
49 6 });
50 }
51 6 } };
52 6 $top->each_match_of(AnonymousSubroutine => $make_tf->('do '));
53 6 $top->each_match_of(SubroutineDeclaration => $make_tf->(''));
54 }
55  
56 0 ▶sub check_bail_out_early {
Subroutine check_bail_out_early: not called CC=1 SCAR=6.9
Pod undocumented
57 0 my ($self, $top) = @_;
58 0 $top->text !~ m/ \b state \b /xs;
59 }
60  
61 1 1;
62 __END__
« Babble/Plugin/DefinedOr.pm ↑ Summary Babble.pm »