lib/Perl/ToPerl6/Transformer/Pragmas/RewriteConstants.pm

filter: Statementstmt 62.9% 34 / 54 Branchbran 25.0% 3 / 12 Conditioncond 57.1% 12 / 21 MC/DCmcdc 0.0% 0 / 11 Subroutinesub 100% 12 / 12 Podpod 60.0% 3 / 5 totaltotal 55.6% 64 / 115 CC 14 SCAR 36.3
CC
14
Cov
56%
transform
66.4
BEGIN
1.0
BEGIN
1.0
CRAP 37.6
« lib/Perl/ToPerl6/Transformer/ModuleSpecific/Exporter.pm ↑ Summary lib/Perl/ToPerl6/Transformer/CompoundStatements/RewriteMapGreps.pm »
1 package Perl::ToPerl6::Transformer::Pragmas::RewriteConstants;
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 insert_leading_whitespace
11 remove_trailing_whitespace
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 Readonly into constant};
19 17 Readonly::Scalar my $EXPL => q{Perl6 has real constants};
20  
21 #-----------------------------------------------------------------------------
22  
23 38 ▶sub supported_parameters { return () }
Subroutine supported_parameters: called CC=1 SCAR=0.0
Pod undocumented
24 38 ▶sub default_necessity { return $NECESSITY_HIGHEST }
Subroutine default_necessity: called CC=1 SCAR=0.0
Pod documented
25 24 ▶sub default_themes { return qw( core ) }
Subroutine default_themes: called CC=1 SCAR=0.0
Pod documented
26 5 ▶sub applies_to { return 'PPI::Statement' }
Subroutine applies_to: called CC=1 SCAR=0.0
Pod documented
27  
28 #-----------------------------------------------------------------------------
29  
30 17 my %map = (
31 'my' => 1,
32 'our' => 1
33 );
34  
35 #
36 # Readonly our @foo => ('a', 'b') --> our constant @foo = ('a', 'b')
37 #
38 11 ▶sub transform {
Subroutine transform: called CC=14 SCAR=42.0
Pod undocumented
39 11 my ($self, $elem, $doc) = @_;
40 11 ▶ return unless $elem and $elem->first_element;
Branch: 1 branch
BranchTrueFalseTotal
unless $elem and $elem->first_element 0 11 11
Condition33%1/3
$elem and $elem->first_element
!ll&&!rl&&r
0011
MC/DC0%0/2
$elem and $elem->first_element
$elem $elem->first_element
Truth table33%1/3
A and B
A= $elemB= $elem->first_element
ABresult
0X0
100
111
41  
42 11 my $head = $elem->first_element;
43 11 my $current = $head;
44  
45 11 ▶ if ( $current->isa('PPI::Token::Word') and
Branch: 2 branches
BranchTrueFalseTotal
if ($current->isa('PPI::Token::Word') and $current->content =~ /^Readonly/) { } 0 11 11
elsif ($head->isa('PPI::Token::Word') and $head->content eq 'use' and $head->snext_sibling and $head->snext_sibling->isa('PPI::Token::Word') and $head->snext_sibling->content eq 'constant') { } 0 21 21
Condition66%2/3
$current->isa("PPI::Token::Word") and $current->content =~ /^Readonly/
!ll&&!rl&&r
290
MC/DC0%0/2
$current->isa("PPI::Token::Word") and $current->content =~ /^Readonly/
$current->isa("PPI::Token::Word") $current->content =~ /^Readonly/
Truth table66%2/3
A and B
A= $current->isa("PPI::Token::Word")B= $current->content =~ /^Readonly/
ABresult
0X0
100
111
46 $current->content =~ m{^Readonly} ) {
47  
48 0 $current->set_content('constant');
49 0 remove_trailing_whitespace($current);
50  
51 0 $current = $current->snext_sibling;
52  
53 0 ▶ if ( exists $map{$current->content} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $map{$current->content}) 0 0 0
54 0 $head->insert_before(
55 PPI::Token::Word->new($current->content)
56 );
57  
58 0 insert_leading_whitespace($head);
59  
60 0 my $temp = $current;
61 0 $current = $current->snext_sibling;
62  
63 0 $temp->remove;
64 }
65 0 ▶ if ( $current->content =~ / ^ ( \$ | \@ ) /x ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($current->content =~ / ^ ( \$ | \@ ) /x) 0 0 0
66 0 my $new_content = $current->content;
67 0 $new_content =~ s< ^ ( \$ | \@ ) ><>x;
68 0 $current->set_content($new_content);
69 }
70  
71 0 $current = $current->snext_sibling;
72  
73 0 $current->set_content('=');
74 }
75 ▶ elsif ( $head->isa('PPI::Token::Word') and
Condition75%9/12
$head->isa("PPI::Token::Word") and $head->content eq "use" and $head->snext_sibling and $head->snext_sibling->isa("PPI::Token::Word") and $head->snext_sibling->content eq "constant"
!ll&&!rl&&r
1010
$head->isa("PPI::Token::Word") and $head->content eq "use" and $head->snext_sibling and $head->snext_sibling->isa("PPI::Token::Word")
!ll&&!rl&&r
1001
$head->isa("PPI::Token::Word") and $head->content eq "use" and $head->snext_sibling
!ll&&!rl&&r
1001
$head->isa("PPI::Token::Word") and $head->content eq "use"
!ll&&!rl&&r
281
MC/DC0%0/5
$head->isa("PPI::Token::Word") and $head->content eq "use" and $head->snext_sibling and $head->snext_sibling->isa("PPI::Token::Word") and $head->snext_sibling->content eq "constant"
$head->isa("PPI::Token::Word") $head->content eq "use" $head->snext_sibling $head->snext_sibling->isa("PPI::Token::Word") $head->snext_sibling->content eq "constant"
Truth table50%3/6
A and B and C and D and E
A= $head->isa("PPI::Token::Word")B= $head->content eq "use"C= $head->snext_siblingD= $head->snext_sibling->isa("PPI::Token::Word")E= $head->snext_sibling->content eq "constant"
ABCDEresult
0XXXX0
10XXX0
110XX0
1110X0
111100
111111
76 $head->content eq 'use' and
77 $head->snext_sibling and
78 $head->snext_sibling->isa('PPI::Token::Word') and
79 $head->snext_sibling->content eq 'constant' ) {
80  
81 0 ▶ while ( $current->snext_sibling and $current->content ne '=>' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($current->snext_sibling and $current->content ne "=>") 0 0 0
Condition0%0/3
$current->snext_sibling and $current->content ne "=>"
!ll&&!rl&&r
000
MC/DC0%0/2
$current->snext_sibling and $current->content ne "=>"
$current->snext_sibling $current->content ne "=>"
Truth table0%0/3
A and B
A= $current->snext_siblingB= $current->content ne "=>"
ABresult
0X0
100
111
82 0 $current = $current->snext_sibling;
83 }
84 0 $current->set_content('=');
85  
86 0 remove_trailing_whitespace($head);
87 0 $head->remove;
88 }
89  
90 11 return $self->transformation( $DESC, $EXPL, $elem );
91 }
92  
93 17 1;
94  
95 #-----------------------------------------------------------------------------
96  
97 __END__
« lib/Perl/ToPerl6/Transformer/ModuleSpecific/Exporter.pm ↑ Summary lib/Perl/ToPerl6/Transformer/CompoundStatements/RewriteMapGreps.pm »