line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Perl::ToPerl6::Transformer::Variables::FormatSigils; |
2
|
|
|
|
|
|
|
|
3
|
17
|
|
|
17
|
|
11404
|
use 5.006001; |
|
17
|
|
|
|
|
51
|
|
4
|
17
|
|
|
17
|
|
82
|
use strict; |
|
17
|
|
|
|
|
27
|
|
|
17
|
|
|
|
|
368
|
|
5
|
17
|
|
|
17
|
|
70
|
use warnings; |
|
17
|
|
|
|
|
63
|
|
|
17
|
|
|
|
|
404
|
|
6
|
17
|
|
|
17
|
|
70
|
use Readonly; |
|
17
|
|
|
|
|
24
|
|
|
17
|
|
|
|
|
803
|
|
7
|
|
|
|
|
|
|
|
8
|
17
|
|
|
17
|
|
76
|
use Perl::ToPerl6::Utils qw{ :characters :severities }; |
|
17
|
|
|
|
|
29
|
|
|
17
|
|
|
|
|
875
|
|
9
|
|
|
|
|
|
|
|
10
|
17
|
|
|
17
|
|
4156
|
use base 'Perl::ToPerl6::Transformer'; |
|
17
|
|
|
|
|
25
|
|
|
17
|
|
|
|
|
6751
|
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
our $VERSION = '0.03'; |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
#----------------------------------------------------------------------------- |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
Readonly::Scalar my $DESC => q{Transform $x[0] to @x[0]}; |
17
|
|
|
|
|
|
|
Readonly::Scalar my $EXPL => |
18
|
|
|
|
|
|
|
q{Perl6 uses the data type as the sigil now, not the context desired}; |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
#----------------------------------------------------------------------------- |
21
|
|
|
|
|
|
|
|
22
|
40
|
|
|
40
|
0
|
1148
|
sub supported_parameters { return () } |
23
|
30
|
|
|
30
|
1
|
133
|
sub default_severity { return $SEVERITY_HIGHEST } |
24
|
25
|
|
|
25
|
1
|
101
|
sub default_themes { return qw(core bugs) } |
25
|
|
|
|
|
|
|
sub applies_to { |
26
|
4
|
|
|
4
|
1
|
13
|
return 'PPI::Token::Symbol', |
27
|
|
|
|
|
|
|
'PPI::Token::ArrayIndex' |
28
|
|
|
|
|
|
|
} |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
#----------------------------------------------------------------------------- |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
# |
33
|
|
|
|
|
|
|
# %foo --> %foo |
34
|
|
|
|
|
|
|
# $foo{a} --> %foo{a} # Note it does not pointify braces. |
35
|
|
|
|
|
|
|
# @foo --> @foo |
36
|
|
|
|
|
|
|
# $foo[1] --> @foo[1] |
37
|
|
|
|
|
|
|
# |
38
|
|
|
|
|
|
|
sub transform { |
39
|
5
|
|
|
5
|
0
|
7
|
my ($self, $elem, $doc) = @_; |
40
|
5
|
50
|
|
|
|
25
|
if ( $elem->isa('PPI::Token::ArrayIndex') ) { |
41
|
0
|
|
|
|
|
0
|
my $content = $elem->content; |
42
|
|
|
|
|
|
|
|
43
|
0
|
|
|
|
|
0
|
$content =~ s{\$#}{}; |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
# |
46
|
|
|
|
|
|
|
# There's a bug that causes $elem->parent to go away here. |
47
|
|
|
|
|
|
|
# Not sure if it's PPI or not... |
48
|
|
|
|
|
|
|
# |
49
|
0
|
0
|
|
|
|
0
|
unless ( $elem->parent ) { |
50
|
0
|
|
|
|
|
0
|
warn "XXX PPI bug triggered\n"; |
51
|
0
|
|
|
|
|
0
|
return; |
52
|
|
|
|
|
|
|
} |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
$elem->insert_before( |
55
|
0
|
|
|
|
|
0
|
PPI::Token::Symbol->new('@' . $content) |
56
|
|
|
|
|
|
|
); |
57
|
0
|
|
|
|
|
0
|
$elem->insert_before( |
58
|
|
|
|
|
|
|
PPI::Token::Symbol->new('.') |
59
|
|
|
|
|
|
|
); |
60
|
0
|
|
|
|
|
0
|
$elem->insert_before( |
61
|
|
|
|
|
|
|
PPI::Token::Word->new('end') |
62
|
|
|
|
|
|
|
); |
63
|
0
|
|
|
|
|
0
|
$elem->delete; |
64
|
|
|
|
|
|
|
} |
65
|
|
|
|
|
|
|
else { |
66
|
5
|
100
|
|
|
|
17
|
return if $elem->raw_type eq '@'; |
67
|
4
|
50
|
|
|
|
41
|
return if $elem->raw_type eq '%'; |
68
|
|
|
|
|
|
|
|
69
|
4
|
100
|
|
|
|
32
|
if ( $elem->next_sibling ) { |
70
|
3
|
|
|
|
|
71
|
my $subscript = $elem->snext_sibling; |
71
|
3
|
50
|
|
|
|
73
|
return unless $subscript->isa('PPI::Structure::Subscript'); |
72
|
0
|
|
|
|
|
0
|
my $new_content = $elem->content; |
73
|
|
|
|
|
|
|
|
74
|
0
|
0
|
|
|
|
0
|
if ( $subscript->start eq '[' ) { |
|
|
0
|
|
|
|
|
|
75
|
0
|
|
|
|
|
0
|
substr($new_content, 0, 1) = '@'; |
76
|
|
|
|
|
|
|
} |
77
|
|
|
|
|
|
|
elsif ( $subscript->start eq '{' ) { |
78
|
0
|
|
|
|
|
0
|
substr($new_content, 0, 1) = '%'; |
79
|
|
|
|
|
|
|
} |
80
|
0
|
|
|
|
|
0
|
$elem->set_content( $new_content ); |
81
|
|
|
|
|
|
|
} |
82
|
|
|
|
|
|
|
} |
83
|
|
|
|
|
|
|
|
84
|
1
|
|
|
|
|
21
|
return $self->transformation( $DESC, $EXPL, $elem ); |
85
|
|
|
|
|
|
|
} |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
1; |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
#----------------------------------------------------------------------------- |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
__END__ |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
=pod |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
=head1 NAME |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
Perl::ToPerl6::Transformer::Variables::FormatSigils - Give variables their proper sigils. |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
=head1 AFFILIATION |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
This Transformer is part of the core L<Perl::ToPerl6|Perl::ToPerl6> |
103
|
|
|
|
|
|
|
distribution. |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
=head1 DESCRIPTION |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
Perl6 uses the sigil type as the data type now, and this is probably the most common operation people will want to do to their file. This transformer doesn't alter hash keys or array indices, those are left to transformers down the line: |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
@foo = () --> @foo = () |
111
|
|
|
|
|
|
|
$foo[1] --> @foo[1] |
112
|
|
|
|
|
|
|
%foo = () --> %foo = () |
113
|
|
|
|
|
|
|
$foo{a} --> %foo{a} # Not %foo<a> or %foo{'a'} yet. |
114
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
Transforms variables outside of comments, heredocs, strings and POD. |
116
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
=head1 CONFIGURATION |
118
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
This Transformer is not configurable except for the standard options. |
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
=head1 AUTHOR |
122
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
Jeffrey Goff <drforr@pobox.com> |
124
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
=head1 COPYRIGHT |
126
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
Copyright (c) 2015 Jeffrey Goff |
128
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify |
130
|
|
|
|
|
|
|
it under the same terms as Perl itself. |
131
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
=cut |
133
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
############################################################################## |
135
|
|
|
|
|
|
|
# Local Variables: |
136
|
|
|
|
|
|
|
# mode: cperl |
137
|
|
|
|
|
|
|
# cperl-indent-level: 4 |
138
|
|
|
|
|
|
|
# fill-column: 78 |
139
|
|
|
|
|
|
|
# indent-tabs-mode: nil |
140
|
|
|
|
|
|
|
# c-indentation-style: bsd |
141
|
|
|
|
|
|
|
# End: |
142
|
|
|
|
|
|
|
# ex: set ts=8 sts=4 sw=4 tw=78 ft=perl expandtab shiftround : |