File Coverage

blib/lib/Perl/ToPerl6/Transformer/Packages/RewriteUsages.pm
Criterion Covered Total %
statement 22 31 70.9
branch 0 2 0.0
condition 0 6 0.0
subroutine 9 13 69.2
pod 3 5 60.0
total 34 57 59.6


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