line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Perl::ToPerl6::Transformer::CompoundStatements::FormatConditionals; |
2
|
|
|
|
|
|
|
|
3
|
17
|
|
|
17
|
|
11823
|
use 5.006001; |
|
17
|
|
|
|
|
51
|
|
4
|
17
|
|
|
17
|
|
81
|
use strict; |
|
17
|
|
|
|
|
41
|
|
|
17
|
|
|
|
|
457
|
|
5
|
17
|
|
|
17
|
|
71
|
use warnings; |
|
17
|
|
|
|
|
34
|
|
|
17
|
|
|
|
|
460
|
|
6
|
17
|
|
|
17
|
|
69
|
use Readonly; |
|
17
|
|
|
|
|
28
|
|
|
17
|
|
|
|
|
943
|
|
7
|
|
|
|
|
|
|
|
8
|
17
|
|
|
17
|
|
104
|
use Perl::ToPerl6::Utils qw{ :characters :severities }; |
|
17
|
|
|
|
|
29
|
|
|
17
|
|
|
|
|
1091
|
|
9
|
|
|
|
|
|
|
|
10
|
17
|
|
|
17
|
|
4422
|
use base 'Perl::ToPerl6::Transformer'; |
|
17
|
|
|
|
|
27
|
|
|
17
|
|
|
|
|
6225
|
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
our $VERSION = '0.03'; |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
#----------------------------------------------------------------------------- |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
Readonly::Scalar my $DESC => q{Transform 'if()' to 'if ()'}; |
17
|
|
|
|
|
|
|
Readonly::Scalar my $EXPL => |
18
|
|
|
|
|
|
|
q{if(), elsif() and unless() need whitespace in order to not be interpreted as function calls}; |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
#----------------------------------------------------------------------------- |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
my %map = ( |
23
|
|
|
|
|
|
|
if => 'if', |
24
|
|
|
|
|
|
|
elsif => 'elsif', |
25
|
|
|
|
|
|
|
unless => 'unless', |
26
|
|
|
|
|
|
|
while => 'while', |
27
|
|
|
|
|
|
|
until => 'until', |
28
|
|
|
|
|
|
|
for => 'for', |
29
|
|
|
|
|
|
|
foreach => 'for', |
30
|
|
|
|
|
|
|
); |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
#----------------------------------------------------------------------------- |
33
|
|
|
|
|
|
|
|
34
|
40
|
|
|
40
|
0
|
1511
|
sub supported_parameters { return () } |
35
|
28
|
|
|
28
|
1
|
120
|
sub default_severity { return $SEVERITY_HIGHEST } |
36
|
25
|
|
|
25
|
1
|
83
|
sub default_themes { return qw(core bugs) } |
37
|
|
|
|
|
|
|
sub applies_to { |
38
|
|
|
|
|
|
|
return sub { |
39
|
|
|
|
|
|
|
$_[1]->isa('PPI::Statement::Compound') and |
40
|
61
|
50
|
33
|
61
|
|
709
|
exists $map{$_[1]->first_element->content} and |
41
|
|
|
|
|
|
|
$_[1]->first_element->snext_sibling |
42
|
|
|
|
|
|
|
} |
43
|
4
|
|
|
4
|
1
|
23
|
} |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
#----------------------------------------------------------------------------- |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
sub transform { |
48
|
0
|
|
|
0
|
0
|
|
my ($self, $elem, $doc) = @_; |
49
|
|
|
|
|
|
|
|
50
|
0
|
|
|
|
|
|
my $token = $elem->first_element; |
51
|
|
|
|
|
|
|
|
52
|
0
|
|
|
|
|
|
my $old_content = $token->content; |
53
|
|
|
|
|
|
|
|
54
|
0
|
|
|
|
|
|
$token->set_content($map{$old_content}); |
55
|
|
|
|
|
|
|
|
56
|
0
|
0
|
|
|
|
|
return if $token->next_sibling->isa('PPI::Token::Whitespace'); |
57
|
|
|
|
|
|
|
|
58
|
0
|
|
|
|
|
|
my $space = PPI::Token::Whitespace->new(); |
59
|
0
|
|
|
|
|
|
$space->set_content(' '); |
60
|
0
|
|
|
|
|
|
$token->insert_after( $space ); |
61
|
|
|
|
|
|
|
|
62
|
0
|
|
|
|
|
|
return $self->transformation( $DESC, $EXPL, $elem ); |
63
|
|
|
|
|
|
|
} |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
1; |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
#----------------------------------------------------------------------------- |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
__END__ |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
=pod |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
=head1 NAME |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
Perl::ToPerl6::Transformer::CompoundStatements::FormatConditionals - Format if(), elsif(), unless() |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
=head1 AFFILIATION |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
This Transformer is part of the core L<Perl::ToPerl6|Perl::ToPerl6> |
81
|
|
|
|
|
|
|
distribution. |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
=head1 DESCRIPTION |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
While Perl6 conditionals allow parentheses, they need whitespace between the bareword C<if> and the opening parenthesis to avoid being interpreted as a function call: |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
if(1) { } --> if (1) { } |
89
|
|
|
|
|
|
|
if (1) { } --> if (1) { } |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
=head1 CONFIGURATION |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
This Transformer is not configurable except for the standard options. |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
=head1 AUTHOR |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
Jeffrey Goff <drforr@pobox.com> |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
=head1 COPYRIGHT |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
Copyright (c) 2015 Jeffrey Goff |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify |
104
|
|
|
|
|
|
|
it under the same terms as Perl itself. |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
=cut |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
############################################################################## |
109
|
|
|
|
|
|
|
# Local Variables: |
110
|
|
|
|
|
|
|
# mode: cperl |
111
|
|
|
|
|
|
|
# cperl-indent-level: 4 |
112
|
|
|
|
|
|
|
# fill-column: 78 |
113
|
|
|
|
|
|
|
# indent-tabs-mode: nil |
114
|
|
|
|
|
|
|
# c-indentation-style: bsd |
115
|
|
|
|
|
|
|
# End: |
116
|
|
|
|
|
|
|
# ex: set ts=8 sts=4 sw=4 tw=78 ft=perl expandtab shiftround : |