lib/Perl/ToPerl6/Transformer/Builtins/RewritePrint.pm

filter: Statementstmt 100% 45 / 45 Branchbran 87.5% 7 / 8 Conditioncond 50.0% 15 / 30 MC/DCmcdc 21.4% 3 / 14 Subroutinesub 100% 16 / 16 Podpod 50.0% 3 / 6 totaltotal 74.7% 89 / 119 CC 12 SCAR 12.1
CC
12
Cov
81%
_is_end_of_print_expression
8.1
__ANON__
3.3
__ANON__
3.3
CRAP 3.3
« lib/Perl/ToPerl6/Transformer/CompoundStatements/AddWhitespace.pm ↑ Summary lib/Perl/ToPerl6/Utils/POD.pm »
1 package Perl::ToPerl6::Transformer::Builtins::RewritePrint;
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 remove_trailing_whitespace
12 replace_remainder_with_list
13 17 };
14  
15 17 ▶use base 'Perl::ToPerl6::Transformer';
Subroutine BEGIN: called CC=1 SCAR=0.0
16  
17 #-----------------------------------------------------------------------------
18  
19 17 Readonly::Scalar my $DESC => q{Format 'print FOO $text;' to 'FOO.print($text)'};
20 17 Readonly::Scalar my $EXPL => q{Format 'print FOO $text;' to 'FOO.print($text)'};
21  
22 #-----------------------------------------------------------------------------
23  
24 17 my %map = (
25 print => 1
26 );
27  
28 #-----------------------------------------------------------------------------
29  
30 # Our first usage of the topological sorting.
31 #
32 # The change 'print FOO "stuff"' --> 'FOO.print("stuff")' rewrites the Perl5
33 # code to Perl6, so it has to be run *after* the Perl5-Perl6 operator
34 # conversion has taken place.
35 #
36 # It might even be better to rephrase this in terms of:
37 #
38 # "Run this test only after resetting the content of PPI::Token::Operators"
39 # but that feel dangerous and fragile.
40 #
41  
42 31 ▶sub run_after { return 'Operators::FormatOperators' }
Subroutine run_after: called CC=1 SCAR=0.0
Pod undocumented
43 38 ▶sub supported_parameters { return () }
Subroutine supported_parameters: called CC=1 SCAR=0.0
Pod undocumented
44 30 ▶sub default_necessity { return $NECESSITY_HIGHEST }
Subroutine default_necessity: called CC=1 SCAR=0.0
Pod documented
45 24 ▶sub default_themes { return qw( core ) }
Subroutine default_themes: called CC=1 SCAR=0.0
Pod documented
46 5 ▶sub applies_to {
Subroutine applies_to: called CC=1 SCAR=0.3
Pod documented
47 78 ▶ return sub {
Subroutine __ANON__: called CC=3 SCAR=12.0
48 78 ▶ is_ppi_token_word($_[1], %map) and
Branch: 1 branch
BranchTrueFalseTotal
is_ppi_token_word($_[1], %map) and not $_[1]->snext_sibling->snext_sibling->isa("PPI::Token::Operator") && $_[1]->snext_sibling->snext_sibling->content eq "," 4 74 78
Condition50%3/6
is_ppi_token_word($_[1], %map) && !($_[1]->snext_sibling->snext_sibling->isa('PPI::Token::Operator') && $_[1]->snext_sibling->snext_sibling->content eq ',')
!ll&&!rl&&r
7404
$_[1]->snext_sibling->snext_sibling->isa('PPI::Token::Operator') && $_[1]->snext_sibling->snext_sibling->content eq ','
!ll&&!rl&&r
400
MC/DC33%1/3
is_ppi_token_word($_[1], %map) && !($_[1]->snext_sibling->snext_sibling->isa('PPI::Token::Operator') && $_[1]->snext_sibling->snext_sibling->content eq ',')
is_ppi_token_word($_[1], %map) $_[1]->snext_sibling->snext_sibling->isa('PPI::Token::Operator') $_[1]->snext_sibling->snext_sibling->content eq ','
Truth table50%2/4
A && not(B && C)
A= is_ppi_token_word($_[1], %map)B= $_[1]->snext_sibling->snext_sibling->isa('PPI::Token::Operator')C= $_[1]->snext_sibling->snext_sibling->content eq ','
ABCresult
0XX0
1110
10X1
1101
49 not ( $_[1]->snext_sibling
50 ->snext_sibling->isa('PPI::Token::Operator') and
51 $_[1]->snext_sibling
52 ->snext_sibling->content eq ',' )
53 }
54 5 }
55  
56 #-----------------------------------------------------------------------------
57  
58 17 my %postfix_modifier = (
59 if => 1,
60 unless => 1,
61 while => 1,
62 until => 1,
63 for => 1,
64 foreach => 1
65 );
66  
67 17 my %operator = (
68 and => 1,
69 or => 1,
70 xor => 1,
71 '&&' => 1,
72 '||' => 1,
73 '^^' => 1
74 );
75  
76 6 ▶sub _is_end_of_print_expression {
Subroutine _is_end_of_print_expression: called CC=6 SCAR=20.9
77 ( $_[1]->isa('PPI::Token::Structure') and
78 $_[1]->content eq ';' ) or
79 ( $_[1]->isa('PPI::Token::Word') and
80 exists $postfix_modifier{$_[1]->content} ) or
81 ( $_[1]->isa('PPI::Token::Operator') and
82 6 ▶ exists $operator{$_[1]->content} )
Branch: 1 branch
BranchTrueFalseTotal
$_[1]->isa("PPI::Token::Structure") and $_[1]->content eq ";" or $_[1]->isa("PPI::Token::Word") and exists $postfix_modifier{$_[1]->content} or $_[1]->isa("PPI::Token::Operator") and exists $operator{$_[1]->content} 4 2 6
Condition53%8/15
$_[1]->isa('PPI::Token::Structure') && $_[1]->content eq ';' || $_[1]->isa('PPI::Token::Word') && exists $postfix_modifier{$_[1]->content} || $_[1]->isa('PPI::Token::Operator') && exists $operator{$_[1]->content}
l!l&&r!l&&!r
402
$_[1]->isa("PPI::Token::Structure") and $_[1]->content eq ";" or $_[1]->isa("PPI::Token::Word") and exists $postfix_modifier{$_[1]->content}
l!l&&r!l&&!r
402
$_[1]->isa("PPI::Token::Structure") and $_[1]->content eq ";"
!ll&&!rl&&r
204
$_[1]->isa("PPI::Token::Word") and exists $postfix_modifier{$_[1]->content}
!ll&&!rl&&r
200
$_[1]->isa("PPI::Token::Operator") and exists $operator{$_[1]->content}
!ll&&!rl&&r
200
MC/DC16%1/6
$_[1]->isa('PPI::Token::Structure') && $_[1]->content eq ';' || $_[1]->isa('PPI::Token::Word') && exists $postfix_modifier{$_[1]->content} || $_[1]->isa('PPI::Token::Operator') && exists $operator{$_[1]->content}
$_[1]->isa("PPI::Token::Structure") $_[1]->content eq ";" $_[1]->isa("PPI::Token::Word") exists $postfix_modifier{$_[1]->content} $_[1]->isa("PPI::Token::Operator") exists $operator{$_[1]->content}
Truth table13%2/15
A and B or C and D || E and F
A= $_[1]->isa("PPI::Token::Structure")B= $_[1]->content eq ";"C= $_[1]->isa("PPI::Token::Word")D= exists $postfix_modifier{$_[1]->content}E= $_[1]->isa("PPI::Token::Operator")F= exists $operator{$_[1]->content}
ABCDEFresult
11XXXX1
0X11XX1
1011XX1
0X0X111
0X10111
100X111
1010111
0X0X0X0
0X0X100
0X100X0
0X10100
100X0X0
100X100
10100X0
1010100
83 }
84  
85 4 ▶sub transform {
Subroutine transform: called CC=3 SCAR=11.4
Pod undocumented
86 4 my ($self, $elem, $doc) = @_;
87 4 ▶ return unless $elem->snext_sibling and
Branch: 1 branch
BranchTrueFalseTotal
unless $elem->snext_sibling and $elem->snext_sibling->snext_sibling 0 4 4
Condition33%1/3
$elem->snext_sibling and $elem->snext_sibling->snext_sibling
!ll&&!rl&&r
004
MC/DC0%0/2
$elem->snext_sibling and $elem->snext_sibling->snext_sibling
$elem->snext_sibling $elem->snext_sibling->snext_sibling
Truth table33%1/3
A and B
A= $elem->snext_siblingB= $elem->snext_sibling->snext_sibling
ABresult
0X0
100
111
88 $elem->snext_sibling->snext_sibling;
89  
90 4 my $token = $elem->snext_sibling->snext_sibling;
91 replace_remainder_with_list(
92 6 ▶ $token, sub {
Subroutine __ANON__: called CC=3 SCAR=12.0
93 6 ▶ _is_end_of_print_expression(@_) or
Branch: 1 branch
BranchTrueFalseTotal
_is_end_of_print_expression(@_) or $_[1]->isa("PPI::Token::Whitespace") and _is_end_of_print_expression(undef, $_[1]->snext_sibling) 4 2 6
Condition50%3/6
_is_end_of_print_expression(@_) || $_[1]->isa('PPI::Token::Whitespace') && _is_end_of_print_expression(undef, $_[1]->snext_sibling)
l!l&&r!l&&!r
402
$_[1]->isa("PPI::Token::Whitespace") and _is_end_of_print_expression(undef, $_[1]->snext_sibling)
!ll&&!rl&&r
200
MC/DC33%1/3
_is_end_of_print_expression(@_) || $_[1]->isa('PPI::Token::Whitespace') && _is_end_of_print_expression(undef, $_[1]->snext_sibling)
_is_end_of_print_expression(@_) $_[1]->isa("PPI::Token::Whitespace") _is_end_of_print_expression(undef, $_[1]->snext_sibling)
Truth table50%2/4
A || B and C
A= _is_end_of_print_expression(@_)B= $_[1]->isa("PPI::Token::Whitespace")C= _is_end_of_print_expression(undef, $_[1]->snext_sibling)
ABCresult
1XX1
0111
00X0
0100
94 $_[1]->isa('PPI::Token::Whitespace') and
95 _is_end_of_print_expression(undef,$_[1]->snext_sibling);
96 }
97 4 );
98  
99 4 remove_trailing_whitespace($elem);
100  
101 4 my $filehandle_variable = $elem->snext_sibling->clone;
102 4 $elem->snext_sibling->remove;
103  
104 4 remove_trailing_whitespace($elem);
105  
106 4 $elem->insert_before($filehandle_variable);
107 4 $elem->insert_before(
108 PPI::Token::Operator->new('.')
109 );
110  
111 4 return $self->transformation( $DESC, $EXPL, $elem );
112 }
113  
114 17 1;
115  
116 #-----------------------------------------------------------------------------
117  
118 __END__
« lib/Perl/ToPerl6/Transformer/CompoundStatements/AddWhitespace.pm ↑ Summary lib/Perl/ToPerl6/Utils/POD.pm »