line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Perl::ToPerl6::Transformer::Pragmas::RewriteConstants; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
763
|
use 5.006001; |
|
1
|
|
|
|
|
3
|
|
4
|
1
|
|
|
1
|
|
4
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
19
|
|
5
|
1
|
|
|
1
|
|
4
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
20
|
|
6
|
1
|
|
|
1
|
|
4
|
use Readonly; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
90
|
|
7
|
|
|
|
|
|
|
|
8
|
1
|
|
|
1
|
|
5
|
use Perl::ToPerl6::Utils qw{ :severities }; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
45
|
|
9
|
1
|
|
|
|
|
56
|
use Perl::ToPerl6::Utils::PPI qw{ |
10
|
|
|
|
|
|
|
insert_leading_whitespace |
11
|
|
|
|
|
|
|
remove_trailing_whitespace |
12
|
1
|
|
|
1
|
|
107
|
}; |
|
1
|
|
|
|
|
1
|
|
13
|
|
|
|
|
|
|
|
14
|
1
|
|
|
1
|
|
5
|
use base 'Perl::ToPerl6::Transformer'; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
573
|
|
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
#----------------------------------------------------------------------------- |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
Readonly::Scalar my $DESC => q{Transform Readonly into constant}; |
19
|
|
|
|
|
|
|
Readonly::Scalar my $EXPL => q{Perl6 has real constants}; |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
#----------------------------------------------------------------------------- |
22
|
|
|
|
|
|
|
|
23
|
1
|
|
|
1
|
0
|
3
|
sub supported_parameters { return () } |
24
|
1
|
|
|
1
|
1
|
5
|
sub default_necessity { return $NECESSITY_HIGHEST } |
25
|
0
|
|
|
0
|
1
|
|
sub default_themes { return qw( core ) } |
26
|
0
|
|
|
0
|
1
|
|
sub applies_to { return 'PPI::Statement' } |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
#----------------------------------------------------------------------------- |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
my %map = ( |
31
|
|
|
|
|
|
|
'my' => 1, |
32
|
|
|
|
|
|
|
'our' => 1 |
33
|
|
|
|
|
|
|
); |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
# |
36
|
|
|
|
|
|
|
# Readonly our @foo => ('a', 'b') --> our constant @foo = ('a', 'b') |
37
|
|
|
|
|
|
|
# |
38
|
|
|
|
|
|
|
sub transform { |
39
|
0
|
|
|
0
|
0
|
|
my ($self, $elem, $doc) = @_; |
40
|
0
|
0
|
0
|
|
|
|
return unless $elem and $elem->first_element; |
41
|
|
|
|
|
|
|
|
42
|
0
|
|
|
|
|
|
my $head = $elem->first_element; |
43
|
0
|
|
|
|
|
|
my $current = $head; |
44
|
|
|
|
|
|
|
|
45
|
0
|
0
|
0
|
|
|
|
if ( $current->isa('PPI::Token::Word') and |
|
|
0
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
46
|
|
|
|
|
|
|
$current->content =~ m{^Readonly} ) { |
47
|
|
|
|
|
|
|
|
48
|
0
|
|
|
|
|
|
$current->set_content('constant'); |
49
|
0
|
|
|
|
|
|
remove_trailing_whitespace($current); |
50
|
|
|
|
|
|
|
|
51
|
0
|
|
|
|
|
|
$current = $current->snext_sibling; |
52
|
|
|
|
|
|
|
|
53
|
0
|
0
|
|
|
|
|
if ( exists $map{$current->content} ) { |
54
|
0
|
|
|
|
|
|
$head->insert_before( |
55
|
|
|
|
|
|
|
PPI::Token::Word->new($current->content) |
56
|
|
|
|
|
|
|
); |
57
|
|
|
|
|
|
|
|
58
|
0
|
|
|
|
|
|
insert_leading_whitespace($head); |
59
|
|
|
|
|
|
|
|
60
|
0
|
|
|
|
|
|
my $temp = $current; |
61
|
0
|
|
|
|
|
|
$current = $current->snext_sibling; |
62
|
|
|
|
|
|
|
|
63
|
0
|
|
|
|
|
|
$temp->remove; |
64
|
|
|
|
|
|
|
} |
65
|
0
|
0
|
|
|
|
|
if ( $current->content =~ / ^ ( \$ | \@ ) /x ) { |
66
|
0
|
|
|
|
|
|
my $new_content = $current->content; |
67
|
0
|
|
|
|
|
|
$new_content =~ s< ^ ( \$ | \@ ) ><>x; |
68
|
0
|
|
|
|
|
|
$current->set_content($new_content); |
69
|
|
|
|
|
|
|
} |
70
|
|
|
|
|
|
|
|
71
|
0
|
|
|
|
|
|
$current = $current->snext_sibling; |
72
|
|
|
|
|
|
|
|
73
|
0
|
|
|
|
|
|
$current->set_content('='); |
74
|
|
|
|
|
|
|
} |
75
|
|
|
|
|
|
|
elsif ( $head->isa('PPI::Token::Word') and |
76
|
|
|
|
|
|
|
$head->content eq 'use' and |
77
|
|
|
|
|
|
|
$head->snext_sibling and |
78
|
|
|
|
|
|
|
$head->snext_sibling->isa('PPI::Token::Word') and |
79
|
|
|
|
|
|
|
$head->snext_sibling->content eq 'constant' ) { |
80
|
|
|
|
|
|
|
|
81
|
0
|
|
0
|
|
|
|
while ( $current->snext_sibling and $current->content ne '=>' ) { |
82
|
0
|
|
|
|
|
|
$current = $current->snext_sibling; |
83
|
|
|
|
|
|
|
} |
84
|
0
|
|
|
|
|
|
$current->set_content('='); |
85
|
|
|
|
|
|
|
|
86
|
0
|
|
|
|
|
|
remove_trailing_whitespace($head); |
87
|
0
|
|
|
|
|
|
$head->remove; |
88
|
|
|
|
|
|
|
} |
89
|
|
|
|
|
|
|
|
90
|
0
|
|
|
|
|
|
return $self->transformation( $DESC, $EXPL, $elem ); |
91
|
|
|
|
|
|
|
} |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
1; |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
#----------------------------------------------------------------------------- |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
__END__ |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
=pod |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
=head1 NAME |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
Perl::ToPerl6::Transformer::RewriteConstants - Transform Readonly and constant |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
=head1 AFFILIATION |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
This Transformer is part of the core L<Perl::ToPerl6|Perl::ToPerl6> |
109
|
|
|
|
|
|
|
distribution. |
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
=head1 DESCRIPTION |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
Perl6 has real constants, so we don't need modules or pragmas: |
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
use constant FOO => 1 --> constant $FOO = 1 |
117
|
|
|
|
|
|
|
Readonly my @FOO => (1) --> my constant @FOO = (1) |
118
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
=head1 CONFIGURATION |
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
This Transformer is not configurable except for the standard options. |
122
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
=head1 AUTHOR |
124
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
Jeffrey Goff <drforr@pobox.com> |
126
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
=head1 COPYRIGHT |
128
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
Copyright (c) 2015 Jeffrey Goff |
130
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify |
132
|
|
|
|
|
|
|
it under the same terms as Perl itself. |
133
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
=cut |
135
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
############################################################################## |
137
|
|
|
|
|
|
|
# Local Variables: |
138
|
|
|
|
|
|
|
# mode: cperl |
139
|
|
|
|
|
|
|
# cperl-indent-level: 4 |
140
|
|
|
|
|
|
|
# fill-column: 78 |
141
|
|
|
|
|
|
|
# indent-tabs-mode: nil |
142
|
|
|
|
|
|
|
# c-indentation-style: bsd |
143
|
|
|
|
|
|
|
# End: |
144
|
|
|
|
|
|
|
# ex: set ts=8 sts=4 sw=4 tw=78 ft=perl expandtab shiftround : |