lib/Perl/ToPerl6/Transformer/Operators/FormatOperators.pm

filter: Statementstmt 64.5% 31 / 48 Branchbran 5.0% 1 / 20 Conditioncond 33.3% 5 / 15 MC/DCmcdc 0.0% 0 / 6 Subroutinesub 92.3% 12 / 13 Podpod 60.0% 3 / 5 totaltotal 48.6% 52 / 107 CC 15 SCAR 37.9
CC
15
Cov
45%
transform
110.0
__ANON__
14.2
applies_to
1.2
CRAP 44.3
« lib/Perl/ToPerl6/Transformer/Variables/ReplaceUndef.pm ↑ Summary lib/Perl/ToPerl6/Transformer/ModuleSpecific/Exporter.pm »
1 package Perl::ToPerl6::Transformer::Operators::FormatOperators;
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_operator
11 remove_trailing_whitespace
12 insert_trailing_whitespace
13 remove_leading_whitespace
14 insert_leading_whitespace
15 17 };
16  
17 17 ▶use base 'Perl::ToPerl6::Transformer';
Subroutine BEGIN: called CC=1 SCAR=0.0
18  
19 #-----------------------------------------------------------------------------
20  
21 17 Readonly::Scalar my $DESC => q{Transform operators to perl6 equivalents};
22 17 Readonly::Scalar my $EXPL =>
23 q{Operators, notably '->' and '!', change names in Perl6};
24  
25 #-----------------------------------------------------------------------------
26  
27 17 my %after = (
28 and => 1,
29 or => 1,
30 xor => 1,
31 not => 1,
32 cmp => 1,
33 lt => 1,
34 gt => 1,
35 le => 1,
36 ge => 1,
37 eq => 1,
38 ne => 1,
39 );
40  
41 17 my %before = (
42 '<' => 1,
43 '<=' => 1,
44 '<=>' => 1,
45 );
46  
47 17 my %mutate = (
48 # From the unary operators:
49 #
50 # '++', '--' are unchanged.
51 # '!' is unchanged.
52 # 'not' is unchanged.
53  
54 # '^', '!' are changed.
55 '^' => '+^',
56 '!' => '?^',
57 '~' => '+^',
58  
59 # ',' is unchanged.
60 # '+', '-', '*', '/', '%', '**' are unchanged.
61 # '&&', '||', '^' are unchanged.
62 # 'and', 'or', 'xor' are unchanged.
63 # '==', '!=', '<', '>', '<=', '>=' are unchanged.
64 # 'eq', 'ne', 'lt', 'gt', 'le', 'ge' are unchanged.
65  
66 # '<=>' behaves similarly.
67 # 'cmp' is now named 'leg'.
68 # '~~' is unchanged, but the semantics are wildly different.
69 'cmp' => 'leg',
70  
71 # '&', '|', '^' are changed, and string semantics are different.
72 '&' => '+&', '&=' => '+&=',
73 '|' => '+|', '|=' => '+|=',
74 '^' => '+^', '^=' => '+^=',
75  
76 '<<' => '+<', '<<=' => '+<=',
77 '>>' => '+>', '>>=' => '+>=',
78  
79 '.' => '~', '.=' => '~=',
80  
81 '->' => '.',
82  
83 '=~' => '~~',
84 '!~' => '!~~',
85  
86 # And finally, the lone ternary operator:
87 #
88 '?' => '??',
89 ':' => '!!',
90 );
91  
92 #-----------------------------------------------------------------------------
93  
94 38 ▶sub supported_parameters { return () }
Subroutine supported_parameters: called CC=1 SCAR=0.0
Pod undocumented
95 26 ▶sub default_necessity { return $NECESSITY_HIGHEST }
Subroutine default_necessity: called CC=1 SCAR=0.0
Pod documented
96 24 ▶sub default_themes { return qw( core ) }
Subroutine default_themes: called CC=1 SCAR=0.0
Pod documented
97 5 ▶sub applies_to {
Subroutine applies_to: called CC=1 SCAR=1.8
Pod documented
98 78 ▶ return sub {
Subroutine __ANON__: called CC=6 SCAR=26.5
99 78 ▶ is_ppi_token_operator($_[1], %mutate, %before, %after) or
Branch: 1 branch
BranchTrueFalseTotal
is_ppi_token_operator($_[1], %mutate, %before, %after) or $_[1]->isa("PPI::Token::Label") and $_[1]->content =~ /\:$/ and $_[1]->sprevious_sibling and $_[1]->sprevious_sibling->isa("PPI::Token::Operator") and $_[1]->sprevious_sibling->content eq "?" 0 78 78
Condition33%5/15
is_ppi_token_operator($_[1], %mutate, %before, %after) || $_[1]->isa('PPI::Token::Label') && $_[1]->content =~ /\:$/ && $_[1]->sprevious_sibling && $_[1]->sprevious_sibling->isa('PPI::Token::Operator') && $_[1]->sprevious_sibling->content eq '?'
l!l&&r!l&&!r
0078
$_[1]->isa("PPI::Token::Label") and $_[1]->content =~ /\:$/ and $_[1]->sprevious_sibling and $_[1]->sprevious_sibling->isa("PPI::Token::Operator") and $_[1]->sprevious_sibling->content eq "?"
!ll&&!rl&&r
7800
$_[1]->isa("PPI::Token::Label") and $_[1]->content =~ /\:$/ and $_[1]->sprevious_sibling and $_[1]->sprevious_sibling->isa("PPI::Token::Operator")
!ll&&!rl&&r
7800
$_[1]->isa("PPI::Token::Label") and $_[1]->content =~ /\:$/ and $_[1]->sprevious_sibling
!ll&&!rl&&r
7800
$_[1]->isa("PPI::Token::Label") and $_[1]->content =~ /\:$/
!ll&&!rl&&r
7800
MC/DC0%0/6
is_ppi_token_operator($_[1], %mutate, %before, %after) || $_[1]->isa('PPI::Token::Label') && $_[1]->content =~ /\:$/ && $_[1]->sprevious_sibling && $_[1]->sprevious_sibling->isa('PPI::Token::Operator') && $_[1]->sprevious_sibling->content eq '?'
is_ppi_token_operator($_[1], %mutate, %before, %after) $_[1]->isa("PPI::Token::Label") $_[1]->content =~ /\:$/ $_[1]->sprevious_sibling $_[1]->sprevious_sibling->isa("PPI::Token::Operator") $_[1]->sprevious_sibling->content eq "?"
Truth table14%1/7
A || B and C and D and E and F
A= is_ppi_token_operator($_[1], %mutate, %before, %after)B= $_[1]->isa("PPI::Token::Label")C= $_[1]->content =~ /\:$/D= $_[1]->sprevious_siblingE= $_[1]->sprevious_sibling->isa("PPI::Token::Operator")F= $_[1]->sprevious_sibling->content eq "?"
ABCDEFresult
1XXXXX1
0111111
00XXXX0
010XXX0
0110XX0
01110X0
0111100
100 ( $_[1]->isa('PPI::Token::Label') and
101 $_[1]->content =~ /\:$/ and
102 $_[1]->sprevious_sibling and
103 $_[1]->sprevious_sibling->isa('PPI::Token::Operator') and
104 $_[1]->sprevious_sibling->content eq '?' )
105 }
106 5 }
107  
108 #-----------------------------------------------------------------------------
109  
110 0 ▶sub transform {
Subroutine transform: not called CC=10 SCAR=47.0
Pod undocumented
111 0 my ($self, $elem, $doc) = @_;
112 0 ▶ if ( $elem->isa('PPI::Token::Label') ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($elem->isa("PPI::Token::Label")) 0 0 0
113 0 my $old_content = $elem->content;
114  
115 0 $old_content =~ s< : $ ><!!>sx;
116  
117 0 $elem->set_content( $old_content );
118 }
119  
120 # nonassoc ++
121 # nonassoc --
122 # right !
123 # right ~
124 # right \
125 # right +
126 # right -
127 # left *
128 # left %
129  
130 # nonassoc ~~
131 # left &
132 # right *= etc. goto last next redo dump
133  
134 # nonassoc list operators (rightward)
135 # right not
136  
137 0 my $old_content = $elem->content;
138  
139 $elem->set_content( $mutate{$old_content} ) if
140 0 ▶ exists $mutate{$old_content};
Branch: 1 branch
BranchTrueFalseTotal
if exists $mutate{$old_content} 0 0 0
141  
142 0 ▶ if ( $old_content eq '=>' ) { # XXX This is a special case.
Branch: 4 branches
BranchTrueFalseTotal
if ($old_content eq '=>') { } 0 0 0
elsif ($old_content eq 'x') { } 0 0 0
elsif ($old_content eq '..') { } 0 0 0
elsif ($old_content eq '...') { } 0 0 0
143 }
144 elsif ( $old_content eq 'x' ) { # XXX This is a special case.
145 }
146 elsif ( $old_content eq '..' ) { # XXX This is a special case.
147 # List version is unchanged.
148 # Scalar version is now 'ff'
149 0 $elem->set_content('ff XXX');
150 }
151 elsif ( $old_content eq '...' ) { # XXX This is a special case.
152 # List version is unchanged.
153 # Scalar version is now 'fff'
154 0 $elem->set_content('fff XXX');
155 }
156  
157 0 ▶ if ( $elem->content eq '.' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($elem->content eq ".") 0 0 0
158 0 remove_trailing_whitespace($elem);
159 0 remove_leading_whitespace($elem);
160 }
161  
162 0 ▶ if ( $before{$elem->content} ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($before{$elem->content}) { } 0 0 0
elsif ($after{$elem->content}) { } 0 0 0
163 0 insert_leading_whitespace($elem);
164 }
165 elsif ( $after{$elem->content} ) {
166 0 insert_trailing_whitespace($elem);
167 }
168  
169 0 return $self->transformation( $DESC, $EXPL, $elem );
170 }
171  
172 17 1;
173  
174 #-----------------------------------------------------------------------------
175  
176 __END__
« lib/Perl/ToPerl6/Transformer/Variables/ReplaceUndef.pm ↑ Summary lib/Perl/ToPerl6/Transformer/ModuleSpecific/Exporter.pm »