line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Perl::ToPerl6::Transformer::Builtins::RewritePrint; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
740
|
use 5.006001; |
|
1
|
|
|
|
|
4
|
|
4
|
1
|
|
|
1
|
|
5
|
use strict; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
19
|
|
5
|
1
|
|
|
1
|
|
4
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
21
|
|
6
|
1
|
|
|
1
|
|
4
|
use Readonly; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
52
|
|
7
|
|
|
|
|
|
|
|
8
|
1
|
|
|
1
|
|
8
|
use Perl::ToPerl6::Utils qw{ :severities }; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
75
|
|
9
|
1
|
|
|
|
|
57
|
use Perl::ToPerl6::Utils::PPI qw{ |
10
|
|
|
|
|
|
|
is_ppi_token_word |
11
|
|
|
|
|
|
|
remove_trailing_whitespace |
12
|
|
|
|
|
|
|
replace_remainder_with_list |
13
|
1
|
|
|
1
|
|
141
|
}; |
|
1
|
|
|
|
|
3
|
|
14
|
|
|
|
|
|
|
|
15
|
1
|
|
|
1
|
|
5
|
use base 'Perl::ToPerl6::Transformer'; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
527
|
|
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
#----------------------------------------------------------------------------- |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
Readonly::Scalar my $DESC => q{Format 'print FOO $text;' to 'FOO.print($text)'}; |
20
|
|
|
|
|
|
|
Readonly::Scalar my $EXPL => q{Format 'print FOO $text;' to 'FOO.print($text)'}; |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
#----------------------------------------------------------------------------- |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
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
|
1
|
|
|
1
|
0
|
4
|
sub run_after { return 'Operators::FormatOperators' } |
43
|
1
|
|
|
1
|
0
|
3
|
sub supported_parameters { return () } |
44
|
1
|
|
|
1
|
1
|
5
|
sub default_necessity { return $NECESSITY_HIGHEST } |
45
|
0
|
|
|
0
|
1
|
|
sub default_themes { return qw( core ) } |
46
|
|
|
|
|
|
|
sub applies_to { |
47
|
|
|
|
|
|
|
return sub { |
48
|
0
|
0
|
0
|
0
|
|
|
is_ppi_token_word($_[1], %map) and |
49
|
|
|
|
|
|
|
not ( $_[1]->snext_sibling |
50
|
|
|
|
|
|
|
->snext_sibling->isa('PPI::Token::Operator') and |
51
|
|
|
|
|
|
|
$_[1]->snext_sibling |
52
|
|
|
|
|
|
|
->snext_sibling->content eq ',' ) |
53
|
|
|
|
|
|
|
} |
54
|
0
|
|
|
0
|
1
|
|
} |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
#----------------------------------------------------------------------------- |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
my %postfix_modifier = ( |
59
|
|
|
|
|
|
|
if => 1, |
60
|
|
|
|
|
|
|
unless => 1, |
61
|
|
|
|
|
|
|
while => 1, |
62
|
|
|
|
|
|
|
until => 1, |
63
|
|
|
|
|
|
|
for => 1, |
64
|
|
|
|
|
|
|
foreach => 1 |
65
|
|
|
|
|
|
|
); |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
my %operator = ( |
68
|
|
|
|
|
|
|
and => 1, |
69
|
|
|
|
|
|
|
or => 1, |
70
|
|
|
|
|
|
|
xor => 1, |
71
|
|
|
|
|
|
|
'&&' => 1, |
72
|
|
|
|
|
|
|
'||' => 1, |
73
|
|
|
|
|
|
|
'^^' => 1 |
74
|
|
|
|
|
|
|
); |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
sub _is_end_of_print_expression { |
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
|
0
|
0
|
0
|
0
|
|
|
exists $operator{$_[1]->content} ) |
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
83
|
|
|
|
|
|
|
} |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
sub transform { |
86
|
0
|
|
|
0
|
0
|
|
my ($self, $elem, $doc) = @_; |
87
|
0
|
0
|
0
|
|
|
|
return unless $elem->snext_sibling and |
88
|
|
|
|
|
|
|
$elem->snext_sibling->snext_sibling; |
89
|
|
|
|
|
|
|
|
90
|
0
|
|
|
|
|
|
my $token = $elem->snext_sibling->snext_sibling; |
91
|
|
|
|
|
|
|
replace_remainder_with_list( |
92
|
|
|
|
|
|
|
$token, sub { |
93
|
0
|
0
|
0
|
0
|
|
|
_is_end_of_print_expression(@_) or |
94
|
|
|
|
|
|
|
$_[1]->isa('PPI::Token::Whitespace') and |
95
|
|
|
|
|
|
|
_is_end_of_print_expression(undef,$_[1]->snext_sibling); |
96
|
|
|
|
|
|
|
} |
97
|
0
|
|
|
|
|
|
); |
98
|
|
|
|
|
|
|
|
99
|
0
|
|
|
|
|
|
remove_trailing_whitespace($elem); |
100
|
|
|
|
|
|
|
|
101
|
0
|
|
|
|
|
|
my $filehandle_variable = $elem->snext_sibling->clone; |
102
|
0
|
|
|
|
|
|
$elem->snext_sibling->remove; |
103
|
|
|
|
|
|
|
|
104
|
0
|
|
|
|
|
|
remove_trailing_whitespace($elem); |
105
|
|
|
|
|
|
|
|
106
|
0
|
|
|
|
|
|
$elem->insert_before($filehandle_variable); |
107
|
0
|
|
|
|
|
|
$elem->insert_before( |
108
|
|
|
|
|
|
|
PPI::Token::Operator->new('.') |
109
|
|
|
|
|
|
|
); |
110
|
|
|
|
|
|
|
|
111
|
0
|
|
|
|
|
|
return $self->transformation( $DESC, $EXPL, $elem ); |
112
|
|
|
|
|
|
|
} |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
1; |
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
#----------------------------------------------------------------------------- |
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
__END__ |
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
=pod |
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
=head1 NAME |
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
Perl::ToPerl6::Transformer::Builtins::RewritePrint - Format 'print $fh "expr"' |
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
=head1 AFFILIATION |
128
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
This Transformer is part of the core L<Perl::ToPerl6|Perl::ToPerl6> |
130
|
|
|
|
|
|
|
distribution. |
131
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
=head1 DESCRIPTION |
134
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
Perl6 now uses a C<print> method on filehandles as opposed to the old C<print $fh>: |
136
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
print $fh $x --> $fh.print($x) |
138
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
Transforms variables outside of comments, heredocs, strings and POD. |
140
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
=head1 CONFIGURATION |
142
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
This Transformer is not configurable except for the standard options. |
144
|
|
|
|
|
|
|
|
145
|
|
|
|
|
|
|
=head1 AUTHOR |
146
|
|
|
|
|
|
|
|
147
|
|
|
|
|
|
|
Jeffrey Goff <drforr@pobox.com> |
148
|
|
|
|
|
|
|
|
149
|
|
|
|
|
|
|
=head1 COPYRIGHT |
150
|
|
|
|
|
|
|
|
151
|
|
|
|
|
|
|
Copyright (c) 2015 Jeffrey Goff |
152
|
|
|
|
|
|
|
|
153
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify |
154
|
|
|
|
|
|
|
it under the same terms as Perl itself. |
155
|
|
|
|
|
|
|
|
156
|
|
|
|
|
|
|
=cut |
157
|
|
|
|
|
|
|
|
158
|
|
|
|
|
|
|
############################################################################## |
159
|
|
|
|
|
|
|
# Local Variables: |
160
|
|
|
|
|
|
|
# mode: cperl |
161
|
|
|
|
|
|
|
# cperl-indent-level: 4 |
162
|
|
|
|
|
|
|
# fill-column: 78 |
163
|
|
|
|
|
|
|
# indent-tabs-mode: nil |
164
|
|
|
|
|
|
|
# c-indentation-style: bsd |
165
|
|
|
|
|
|
|
# End: |
166
|
|
|
|
|
|
|
# ex: set ts=8 sts=4 sw=4 tw=78 ft=perl expandtab shiftround : |