line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Perl::ToPerl6::Transformer::BasicTypes::Strings::RewriteHereDocs; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
782
|
use 5.006001; |
|
1
|
|
|
|
|
3
|
|
4
|
1
|
|
|
1
|
|
4
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
18
|
|
5
|
1
|
|
|
1
|
|
4
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
25
|
|
6
|
1
|
|
|
1
|
|
4
|
use Readonly; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
40
|
|
7
|
|
|
|
|
|
|
|
8
|
1
|
|
|
1
|
|
4
|
use Perl::ToPerl6::Utils qw{ :severities }; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
45
|
|
9
|
|
|
|
|
|
|
|
10
|
1
|
|
|
1
|
|
117
|
use base 'Perl::ToPerl6::Transformer'; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
350
|
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
#----------------------------------------------------------------------------- |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
Readonly::Scalar my $DESC => q{Transform <<EOF to q:to/EOF/}; |
15
|
|
|
|
|
|
|
Readonly::Scalar my $EXPL => q{Perl6 heredocs now have more flexibility}; |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
#----------------------------------------------------------------------------- |
18
|
|
|
|
|
|
|
|
19
|
1
|
|
|
1
|
0
|
3
|
sub supported_parameters { return () } |
20
|
1
|
|
|
1
|
1
|
4
|
sub default_necessity { return $NECESSITY_HIGHEST } |
21
|
0
|
|
|
0
|
1
|
|
sub default_themes { return qw( core ) } |
22
|
0
|
|
|
0
|
1
|
|
sub applies_to { return 'PPI::Token::HereDoc' } |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
#----------------------------------------------------------------------------- |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
# |
27
|
|
|
|
|
|
|
# <<EOF --> q:to/EOF/ |
28
|
|
|
|
|
|
|
# |
29
|
|
|
|
|
|
|
sub transform { |
30
|
0
|
|
|
0
|
0
|
|
my ($self, $elem, $doc) = @_; |
31
|
|
|
|
|
|
|
|
32
|
0
|
|
|
|
|
|
my $content = $elem->content; |
33
|
|
|
|
|
|
|
|
34
|
0
|
0
|
|
|
|
|
if ( $content =~ s{<<(\w+)}{q:to/$1/} ) { |
|
|
0
|
|
|
|
|
|
35
|
|
|
|
|
|
|
} |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
# |
38
|
|
|
|
|
|
|
# XXX This breaks PPI::Token::HereDoc encapsulation. |
39
|
|
|
|
|
|
|
# |
40
|
|
|
|
|
|
|
elsif ( $content =~ s{<<'(\s*(\w+))'}{q:to/$2/} ) { |
41
|
0
|
|
|
|
|
|
my $heredoc = $1; |
42
|
0
|
|
|
|
|
|
my $stripped = $2; |
43
|
0
|
|
|
|
|
|
for my $line ( @{ $elem->{_heredoc} } ) { |
|
0
|
|
|
|
|
|
|
44
|
0
|
0
|
|
|
|
|
next unless $line =~ /$heredoc$/; |
45
|
0
|
|
|
|
|
|
$line = $stripped; |
46
|
0
|
|
|
|
|
|
last; |
47
|
|
|
|
|
|
|
} |
48
|
0
|
|
|
|
|
|
$elem->{_terminator} = $1; |
49
|
|
|
|
|
|
|
} |
50
|
|
|
|
|
|
|
|
51
|
0
|
|
|
|
|
|
$elem->set_content( $content ); |
52
|
|
|
|
|
|
|
|
53
|
0
|
|
|
|
|
|
return $self->transformation( $DESC, $EXPL, $elem ); |
54
|
|
|
|
|
|
|
} |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
1; |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
#----------------------------------------------------------------------------- |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
__END__ |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
=pod |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
=head1 NAME |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
Perl::ToPerl6::Transformer::BasicTypes::Strings::RewriteHereDocs - Format <<EOF constructs correctly |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
=head1 AFFILIATION |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
This Transformer is part of the core L<Perl::ToPerl6|Perl::ToPerl6> |
72
|
|
|
|
|
|
|
distribution. |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
=head1 DESCRIPTION |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
Perl6 heredocs now no longer need to be quoted, and the indentation rules differ from perl5. Specifically the old workaround of C<< <<' EOF' >> will have surprising results, because your entire heredoc will be indented by the whitespace amount: |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
<<EOF; --> q:to/EOF/; |
80
|
|
|
|
|
|
|
EOF --> EOF |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
<<' EOF'; --> q:to/EOF/; |
83
|
|
|
|
|
|
|
EOF --> EOF |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
Transforms only heredocs, not POD or comments. |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
=head1 CONFIGURATION |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
This Transformer is not configurable except for the standard options. |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
=head1 AUTHOR |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
Jeffrey Goff <drforr@pobox.com> |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
=head1 COPYRIGHT |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
Copyright (c) 2015 Jeffrey Goff |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify |
100
|
|
|
|
|
|
|
it under the same terms as Perl itself. |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
=cut |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
############################################################################## |
105
|
|
|
|
|
|
|
# Local Variables: |
106
|
|
|
|
|
|
|
# mode: cperl |
107
|
|
|
|
|
|
|
# cperl-indent-level: 4 |
108
|
|
|
|
|
|
|
# fill-column: 78 |
109
|
|
|
|
|
|
|
# indent-tabs-mode: nil |
110
|
|
|
|
|
|
|
# c-indentation-style: bsd |
111
|
|
|
|
|
|
|
# End: |
112
|
|
|
|
|
|
|
# ex: set ts=8 sts=4 sw=4 tw=78 ft=perl expandtab shiftround : |