line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Perl::ToPerl6::Transformer::CompoundStatements::SwapForArguments; |
2
|
|
|
|
|
|
|
|
3
|
17
|
|
|
17
|
|
11709
|
use 5.006001; |
|
17
|
|
|
|
|
50
|
|
4
|
17
|
|
|
17
|
|
76
|
use strict; |
|
17
|
|
|
|
|
26
|
|
|
17
|
|
|
|
|
366
|
|
5
|
17
|
|
|
17
|
|
191
|
use warnings; |
|
17
|
|
|
|
|
27
|
|
|
17
|
|
|
|
|
438
|
|
6
|
17
|
|
|
17
|
|
68
|
use Readonly; |
|
17
|
|
|
|
|
27
|
|
|
17
|
|
|
|
|
885
|
|
7
|
|
|
|
|
|
|
|
8
|
17
|
|
|
17
|
|
83
|
use Perl::ToPerl6::Utils qw{ :characters :severities }; |
|
17
|
|
|
|
|
25
|
|
|
17
|
|
|
|
|
920
|
|
9
|
17
|
|
|
17
|
|
4374
|
use Perl::ToPerl6::Utils::PPI qw{ is_ppi_statement_compound }; |
|
17
|
|
|
|
|
26
|
|
|
17
|
|
|
|
|
819
|
|
10
|
|
|
|
|
|
|
|
11
|
17
|
|
|
17
|
|
76
|
use base 'Perl::ToPerl6::Transformer'; |
|
17
|
|
|
|
|
24
|
|
|
17
|
|
|
|
|
7884
|
|
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
our $VERSION = '0.03'; |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
#----------------------------------------------------------------------------- |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
Readonly::Scalar my $DESC => q{Transform 'if()' to 'if ()'}; |
18
|
|
|
|
|
|
|
Readonly::Scalar my $EXPL => |
19
|
|
|
|
|
|
|
q{if(), elsif() and unless() need whitespace in order to not be interpreted as function calls}; |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
#----------------------------------------------------------------------------- |
22
|
|
|
|
|
|
|
|
23
|
33
|
|
|
33
|
0
|
95
|
sub run_after { return 'Operators::FormatOperators' } |
24
|
40
|
|
|
40
|
0
|
1360
|
sub supported_parameters { return () } |
25
|
29
|
|
|
29
|
1
|
128
|
sub default_severity { return $SEVERITY_HIGHEST } |
26
|
25
|
|
|
25
|
1
|
89
|
sub default_themes { return qw(core bugs) } |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
#----------------------------------------------------------------------------- |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
my %map = ( |
31
|
|
|
|
|
|
|
for => 1, |
32
|
|
|
|
|
|
|
foreach => 1, |
33
|
|
|
|
|
|
|
); |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
my %scope_map = ( |
36
|
|
|
|
|
|
|
my => 1, |
37
|
|
|
|
|
|
|
local => 1, |
38
|
|
|
|
|
|
|
our => 1 |
39
|
|
|
|
|
|
|
); |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
sub applies_to { |
42
|
|
|
|
|
|
|
return sub { |
43
|
65
|
50
|
0
|
65
|
|
740
|
is_ppi_statement_compound($_[1], %map) and |
44
|
|
|
|
|
|
|
( $_[1]->schild(1)->isa('PPI::Token::Word') or |
45
|
|
|
|
|
|
|
$_[1]->schild(1)->isa('PPI::Token::Symbol') ) |
46
|
|
|
|
|
|
|
} |
47
|
4
|
|
|
4
|
1
|
25
|
} |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
#----------------------------------------------------------------------------- |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
sub transform { |
52
|
0
|
|
|
0
|
0
|
|
my ($self, $elem, $doc) = @_; |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
# This ASCII art may be of use. |
55
|
|
|
|
|
|
|
# |
56
|
|
|
|
|
|
|
# $elem $loop_variable |
57
|
|
|
|
|
|
|
# | | |
58
|
|
|
|
|
|
|
# | | $whitespace |
59
|
|
|
|
|
|
|
# | | | |
60
|
|
|
|
|
|
|
# [ q{for}, q{ }, q{my}, q{ }, q{$x}, q{ }, q{(@x)} ] |
61
|
|
|
|
|
|
|
# | | | | | | | |
62
|
|
|
|
|
|
|
# | | X X | | | |
63
|
|
|
|
|
|
|
# | | | | | |
64
|
|
|
|
|
|
|
# | | ,-----------' | | |
65
|
|
|
|
|
|
|
# | | | ,------------' | |
66
|
|
|
|
|
|
|
# | | | | ,------------' |
67
|
|
|
|
|
|
|
# | | | | | |
68
|
|
|
|
|
|
|
# V | V V V |
69
|
|
|
|
|
|
|
# [ q{for}, q{ }, q{$x}, q{ }, q{(@x)} ] |
70
|
|
|
|
|
|
|
# | | | | | |
71
|
|
|
|
|
|
|
# | | '------|-----|--------------, |
72
|
|
|
|
|
|
|
# | `-------------, | | |
73
|
|
|
|
|
|
|
# | | | | | |
74
|
|
|
|
|
|
|
# | ,------------' | | | |
75
|
|
|
|
|
|
|
# | | .-------|---' | |
76
|
|
|
|
|
|
|
# | | | | | |
77
|
|
|
|
|
|
|
# | | | | + + | |
78
|
|
|
|
|
|
|
# V V V | | | V |
79
|
|
|
|
|
|
|
# [ q{for}, q{ }, q{(@x)}, q{ }, q{->}, q{ }, q{$x} ] |
80
|
|
|
|
|
|
|
# |
81
|
0
|
0
|
|
|
|
|
if ( $scope_map{$elem->schild(1)->content} ) { |
82
|
0
|
0
|
|
|
|
|
if ( $elem->schild(1)->next_sibling->isa('PPI::Token::Whitespace') ) { |
83
|
0
|
|
|
|
|
|
$elem->schild(1)->next_sibling->remove; |
84
|
|
|
|
|
|
|
} |
85
|
0
|
|
|
|
|
|
$elem->schild(1)->delete; |
86
|
|
|
|
|
|
|
} |
87
|
|
|
|
|
|
|
|
88
|
0
|
|
|
|
|
|
my $whitespace; |
89
|
0
|
0
|
|
|
|
|
if ( $elem->schild(1)->next_sibling->isa('PPI::Token::Whitespace') ) { |
90
|
0
|
|
|
|
|
|
$whitespace = $elem->schild(1)->next_sibling->clone; |
91
|
0
|
|
|
|
|
|
$elem->schild(1)->next_sibling->remove; |
92
|
|
|
|
|
|
|
} |
93
|
0
|
|
|
|
|
|
my $loop_variable = $elem->schild(1)->clone; |
94
|
0
|
|
|
|
|
|
$elem->schild(1)->remove; |
95
|
|
|
|
|
|
|
|
96
|
0
|
|
|
|
|
|
$elem->schild(1)->insert_after( |
97
|
|
|
|
|
|
|
$loop_variable |
98
|
|
|
|
|
|
|
); |
99
|
0
|
|
|
|
|
|
$elem->schild(1)->insert_after( |
100
|
|
|
|
|
|
|
PPI::Token::Whitespace->new(' ') |
101
|
|
|
|
|
|
|
); |
102
|
0
|
|
|
|
|
|
$elem->schild(1)->insert_after( |
103
|
|
|
|
|
|
|
PPI::Token::Operator->new('->') |
104
|
|
|
|
|
|
|
); |
105
|
0
|
|
|
|
|
|
$elem->schild(1)->insert_after( |
106
|
|
|
|
|
|
|
PPI::Token::Whitespace->new(' ') |
107
|
|
|
|
|
|
|
); |
108
|
|
|
|
|
|
|
|
109
|
0
|
|
|
|
|
|
return $self->transformation( $DESC, $EXPL, $elem ); |
110
|
|
|
|
|
|
|
} |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
1; |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
#----------------------------------------------------------------------------- |
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
__END__ |
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
=pod |
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
=head1 NAME |
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
Perl::ToPerl6::Transformer::CompoundStatements::SwapForArguments - Swap C<for my $x ( @x ) { }> --> C<<for ( @x ) -> $x { }>> |
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
=head1 AFFILIATION |
126
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
This Transformer is part of the core L<Perl::ToPerl6|Perl::ToPerl6> |
128
|
|
|
|
|
|
|
distribution. |
129
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
=head1 DESCRIPTION |
132
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
Perl6 formats C<for my $x (@x) { }> as C<<for (@a) -> $x>>: |
134
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
for $x (@x) { } --> for (@x) -> $x { } |
136
|
|
|
|
|
|
|
for my $x (@x) { } --> for (@x) -> $x { } |
137
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
=head1 CONFIGURATION |
139
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
This Transformer is not configurable except for the standard options. |
141
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
=head1 AUTHOR |
143
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
Jeffrey Goff <drforr@pobox.com> |
145
|
|
|
|
|
|
|
|
146
|
|
|
|
|
|
|
=head1 COPYRIGHT |
147
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
Copyright (c) 2015 Jeffrey Goff |
149
|
|
|
|
|
|
|
|
150
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify |
151
|
|
|
|
|
|
|
it under the same terms as Perl itself. |
152
|
|
|
|
|
|
|
|
153
|
|
|
|
|
|
|
=cut |
154
|
|
|
|
|
|
|
|
155
|
|
|
|
|
|
|
############################################################################## |
156
|
|
|
|
|
|
|
# Local Variables: |
157
|
|
|
|
|
|
|
# mode: cperl |
158
|
|
|
|
|
|
|
# cperl-indent-level: 4 |
159
|
|
|
|
|
|
|
# fill-column: 78 |
160
|
|
|
|
|
|
|
# indent-tabs-mode: nil |
161
|
|
|
|
|
|
|
# c-indentation-style: bsd |
162
|
|
|
|
|
|
|
# End: |
163
|
|
|
|
|
|
|
# ex: set ts=8 sts=4 sw=4 tw=78 ft=perl expandtab shiftround : |