line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Perl::ToPerl6::Transformer::Packages::FormatPackageUsages; |
2
|
|
|
|
|
|
|
|
3
|
17
|
|
|
17
|
|
15335
|
use 5.006001; |
|
17
|
|
|
|
|
53
|
|
4
|
17
|
|
|
17
|
|
88
|
use strict; |
|
17
|
|
|
|
|
33
|
|
|
17
|
|
|
|
|
418
|
|
5
|
17
|
|
|
17
|
|
75
|
use warnings; |
|
17
|
|
|
|
|
31
|
|
|
17
|
|
|
|
|
532
|
|
6
|
17
|
|
|
17
|
|
83
|
use Readonly; |
|
17
|
|
|
|
|
26
|
|
|
17
|
|
|
|
|
943
|
|
7
|
|
|
|
|
|
|
|
8
|
17
|
|
|
17
|
|
96
|
use Perl::ToPerl6::Utils qw{ :characters :severities }; |
|
17
|
|
|
|
|
30
|
|
|
17
|
|
|
|
|
1093
|
|
9
|
17
|
|
|
17
|
|
4781
|
use Perl::ToPerl6::Utils::PPI qw{ is_module_name is_pragma }; |
|
17
|
|
|
|
|
30
|
|
|
17
|
|
|
|
|
975
|
|
10
|
|
|
|
|
|
|
|
11
|
17
|
|
|
17
|
|
86
|
use base 'Perl::ToPerl6::Transformer'; |
|
17
|
|
|
|
|
30
|
|
|
17
|
|
|
|
|
6102
|
|
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
our $VERSION = '0.03'; |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
#----------------------------------------------------------------------------- |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
Readonly::Scalar my $DESC => q{Transform 'use Foo;' to 'use Foo:from<Perl5>;'}; |
18
|
|
|
|
|
|
|
Readonly::Scalar my $EXPL => |
19
|
|
|
|
|
|
|
q{Legacy Perl5 classes can be supported using Inline::Perl5 and the :from<Perl5> adverb}; |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
#----------------------------------------------------------------------------- |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
my %map = ( |
24
|
|
|
|
|
|
|
constant => 1 |
25
|
|
|
|
|
|
|
); |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
#----------------------------------------------------------------------------- |
28
|
|
|
|
|
|
|
|
29
|
42
|
|
|
42
|
0
|
1898
|
sub supported_parameters { return () } |
30
|
30
|
|
|
30
|
1
|
129
|
sub default_severity { return $SEVERITY_HIGHEST } |
31
|
25
|
|
|
25
|
1
|
87
|
sub default_themes { return qw(core bugs) } |
32
|
|
|
|
|
|
|
sub applies_to { |
33
|
|
|
|
|
|
|
return sub { |
34
|
|
|
|
|
|
|
$_[1]->isa('PPI::Statement::Include') and |
35
|
|
|
|
|
|
|
not is_pragma($_[1]->child(2)) and |
36
|
|
|
|
|
|
|
is_module_name($_[1]->child(2)) and |
37
|
61
|
50
|
66
|
61
|
|
790
|
not exists $map{$_[1]->child(2)->content} |
|
|
|
66
|
|
|
|
|
38
|
|
|
|
|
|
|
} |
39
|
4
|
|
|
4
|
1
|
21
|
} |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
#----------------------------------------------------------------------------- |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
# |
44
|
|
|
|
|
|
|
# 'use Foo;' --> 'use Foo:from<Perl5>;' |
45
|
|
|
|
|
|
|
# 'use Foo qw(a);' --> 'use Foo:from<Perl5> <a>;' |
46
|
|
|
|
|
|
|
# |
47
|
|
|
|
|
|
|
# Although this module only adjusts the 'Foo' bit. |
48
|
|
|
|
|
|
|
# |
49
|
|
|
|
|
|
|
sub transform { |
50
|
1
|
|
|
1
|
0
|
4
|
my ($self, $elem, $doc) = @_; |
51
|
|
|
|
|
|
|
|
52
|
1
|
|
|
|
|
5
|
my $package_name = $elem->child(2); |
53
|
|
|
|
|
|
|
|
54
|
1
|
|
|
|
|
5
|
my $old_content = $package_name; |
55
|
1
|
|
|
|
|
5
|
$old_content .= ':from<Perl5>'; |
56
|
1
|
|
|
|
|
10
|
$package_name->set_content($old_content); |
57
|
|
|
|
|
|
|
|
58
|
1
|
|
|
|
|
15
|
return $self->transformation( $DESC, $EXPL, $elem ); |
59
|
|
|
|
|
|
|
} |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
1; |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
#----------------------------------------------------------------------------- |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
__END__ |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
=pod |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
=head1 NAME |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
Perl::ToPerl6::Transformer::Packages::FormatPackageUsages - Format 'use Foo;' to 'use Foo:from<Perl5>;' |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
=head1 AFFILIATION |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
This Transformer is part of the core L<Perl::ToPerl6|Perl::ToPerl6> |
77
|
|
|
|
|
|
|
distribution. |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
=head1 DESCRIPTION |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
Since this tool's main purpose is helping to migrate legacy code, it assumes that you've installed L<Inline::Perl5> in order to be able to load Perl5 classes. |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
Perl6 can use Perl5 classes through the use of the C<< :from<Perl5> >> adverb. Since this tool is meant to port existing Perl5 code, the transformer assumes that all C<use> statements it sees are for legacy code. Future transformers may migrate L<Test::More> code to Perl6 L<Test> modules: |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
use Foo; --> use Foo:from<Perl5>; |
87
|
|
|
|
|
|
|
use Foo qw(a b); --> use Foo:from<Perl5> qw(a b); |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
Transforms 'use' statements outside of comments, heredocs, strings and POD. |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
Does B<not> transform C<qw()> statements into their more modern Perl5 C<< <> >> equivalent, that is left to later transformers. |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
=head1 CONFIGURATION |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
This Transformer is not configurable except for the standard options. |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
=head1 AUTHOR |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
Jeffrey Goff <drforr@pobox.com> |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
=head1 COPYRIGHT |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
Copyright (c) 2015 Jeffrey Goff |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify |
106
|
|
|
|
|
|
|
it under the same terms as Perl itself. |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
=cut |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
############################################################################## |
111
|
|
|
|
|
|
|
# Local Variables: |
112
|
|
|
|
|
|
|
# mode: cperl |
113
|
|
|
|
|
|
|
# cperl-indent-level: 4 |
114
|
|
|
|
|
|
|
# fill-column: 78 |
115
|
|
|
|
|
|
|
# indent-tabs-mode: nil |
116
|
|
|
|
|
|
|
# c-indentation-style: bsd |
117
|
|
|
|
|
|
|
# End: |
118
|
|
|
|
|
|
|
# ex: set ts=8 sts=4 sw=4 tw=78 ft=perl expandtab shiftround : |