lib/Perl/ToPerl6/Transformer/CompoundStatements/RewriteMapGreps.pm

filter: Statementstmt 74.3% 29 / 39 Branchbran 10.0% 1 / 10 Conditioncond 0.0% 0 / 15 MC/DCmcdc 0.0% 0 / 7 Subroutinesub 85.7% 12 / 14 Podpod 60.0% 3 / 5 totaltotal 50.0% 45 / 90 CC 11 SCAR 35.5
CC
11
Cov
47%
transform
90.0
_is_end_of_expression
6.0
__ANON__
2.1
CRAP 34.9
« lib/Perl/ToPerl6/Transformer/Pragmas/RewriteConstants.pm ↑ Summary lib/Perl/ToPerl6/Utils/PPI.pm »
1 package Perl::ToPerl6::Transformer::CompoundStatements::RewriteMapGreps;
2  
3 17 ▶use 5.006001;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 17 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 17 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 17 ▶use Readonly;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 17 ▶use Perl::ToPerl6::Utils qw{ :severities };
Subroutine BEGIN: called CC=1 SCAR=0.0
9 17 ▶use Perl::ToPerl6::Utils::PPI qw{
Subroutine BEGIN: called CC=1 SCAR=0.0
10 is_ppi_token_word
11 replace_remainder_with_block
12 17 };
13  
14 17 ▶use base 'Perl::ToPerl6::Transformer';
Subroutine BEGIN: called CC=1 SCAR=0.0
15  
16 #-----------------------------------------------------------------------------
17  
18 17 Readonly::Scalar my $DESC => q{Transform 'given()' to 'given ()'};
19 17 Readonly::Scalar my $EXPL =>
20 q{unless() needs whitespace in order to not be interpreted as a function call};
21  
22 #-----------------------------------------------------------------------------
23  
24 17 my %map = (
25 map => 1,
26 grep => 1
27 );
28  
29 #-----------------------------------------------------------------------------
30  
31 38 ▶sub supported_parameters { return () }
Subroutine supported_parameters: called CC=1 SCAR=0.0
Pod undocumented
32 27 ▶sub default_necessity { return $NECESSITY_HIGHEST }
Subroutine default_necessity: called CC=1 SCAR=0.0
Pod documented
33 24 ▶sub default_themes { return qw( core ) }
Subroutine default_themes: called CC=1 SCAR=0.0
Pod documented
34 5 ▶sub applies_to {
Subroutine applies_to: called CC=1 SCAR=0.2
Pod documented
35 78 ▶ return sub {
Subroutine __ANON__: called CC=2 SCAR=7.6
36 78 ▶ is_ppi_token_word($_[1], %map) and
Branch: 1 branch
BranchTrueFalseTotal
is_ppi_token_word($_[1], %map) and $_[1]->snext_sibling 0 78 78
37 $_[1]->snext_sibling
38 }
39 5 }
40  
41 #-----------------------------------------------------------------------------
42  
43 0 ▶sub _is_end_of_expression {
Subroutine _is_end_of_expression: not called CC=2 SCAR=17.9
44 0 ▶ $_[1]->isa('PPI::Token::Operator') and
Branch: 1 branch
BranchTrueFalseTotal
$_[1]->isa("PPI::Token::Operator") and $_[1]->content eq "," 0 0 0
45 $_[1]->content eq ',';
46 }
47  
48 0 ▶sub transform {
Subroutine transform: not called CC=9 SCAR=45.0
Pod undocumented
49 0 my ($self, $elem, $doc) = @_;
50  
51 #
52 # XXX This is worrisome, as this test should not need to be done.
53 # XXX The applies_to() method above implies that $elem should have an
54 # XXX snext_sibling by the time it gets here.
55 #
56 0 ▶ return unless $elem->snext_sibling;
Branch: 1 branch
BranchTrueFalseTotal
unless $elem->snext_sibling 0 0 0
57 0 my $token = $elem->snext_sibling;
58  
59 0 ▶ if ( $token->isa('PPI::Structure::Block') and
Branch: 1 branch
BranchTrueFalseTotal
if ($token->isa('PPI::Structure::Block') and $token->start and $token->start eq '{' and $token->finish and $token->finish eq '}') { } 0 0 0
Condition0%0/12
$token->isa("PPI::Structure::Block") and $token->start and $token->start eq "{" and $token->finish and $token->finish eq "}"
!ll&&!rl&&r
000
$token->isa("PPI::Structure::Block") and $token->start and $token->start eq "{" and $token->finish
!ll&&!rl&&r
000
$token->isa("PPI::Structure::Block") and $token->start and $token->start eq "{"
!ll&&!rl&&r
000
$token->isa("PPI::Structure::Block") and $token->start
!ll&&!rl&&r
000
MC/DC0%0/5
$token->isa("PPI::Structure::Block") and $token->start and $token->start eq "{" and $token->finish and $token->finish eq "}"
$token->isa("PPI::Structure::Block") $token->start $token->start eq "{" $token->finish $token->finish eq "}"
Truth table0%0/6
A and B and C and D and E
A= $token->isa("PPI::Structure::Block")B= $token->startC= $token->start eq "{"D= $token->finishE= $token->finish eq "}"
ABCDEresult
0XXXX0
10XXX0
110XX0
1110X0
111100
111111
60 $token->start and
61 $token->start eq '{' and
62 $token->finish and
63 $token->finish eq '}' ) {
64 0 ▶ return if $token->snext_sibling and
Branch: 1 branch
BranchTrueFalseTotal
if $token->snext_sibling and _is_end_of_expression(undef, $token->snext_sibling) 0 0 0
Condition0%0/3
$token->snext_sibling and _is_end_of_expression(undef, $token->snext_sibling)
!ll&&!rl&&r
000
MC/DC0%0/2
$token->snext_sibling and _is_end_of_expression(undef, $token->snext_sibling)
$token->snext_sibling _is_end_of_expression(undef, $token->snext_sibling)
Truth table0%0/3
A and B
A= $token->snext_siblingB= _is_end_of_expression(undef, $token->snext_sibling)
ABresult
0X0
100
111
65 _is_end_of_expression(undef,$token->snext_sibling);
66 0 my $comma = PPI::Token::Operator->new(',');
67 0 $token->insert_after( $comma );
68 }
69 else {
70 0 replace_remainder_with_block($token, \&_is_end_of_expression );
71 }
72  
73 0 return $self->transformation( $DESC, $EXPL, $elem );
74 }
75  
76 17 1;
77  
78 #-----------------------------------------------------------------------------
79  
80 __END__
« lib/Perl/ToPerl6/Transformer/Pragmas/RewriteConstants.pm ↑ Summary lib/Perl/ToPerl6/Utils/PPI.pm »