File Coverage

blib/lib/Perl/ToPerl6/Transformer/Pragmas/FormatPragmas.pm
Criterion Covered Total %
statement 25 28 89.2
branch 1 2 50.0
condition 3 6 50.0
subroutine 12 13 92.3
pod 3 5 60.0
total 44 54 81.4


line stmt bran cond sub pod time code
1             package Perl::ToPerl6::Transformer::Pragmas::FormatPragmas;
2              
3 17     17   12255 use 5.006001;
  17         1038  
4 17     17   78 use strict;
  17         23  
  17         374  
5 17     17   73 use warnings;
  17         33  
  17         412  
6 17     17   65 use Readonly;
  17         27  
  17         879  
7              
8 17     17   81 use Perl::ToPerl6::Utils qw{ :characters :severities };
  17         30  
  17         875  
9 17     17   4149 use Perl::ToPerl6::Utils::PPI qw{ is_version_number is_pragma };
  17         28  
  17         909  
10              
11 17     17   75 use base 'Perl::ToPerl6::Transformer';
  17         26  
  17         5009  
12              
13             our $VERSION = '0.03';
14              
15             #-----------------------------------------------------------------------------
16              
17             Readonly::Scalar my $DESC => q{Delete unnecessary pragmas};
18             Readonly::Scalar my $EXPL =>
19             q{Pragmas such as 'strict', 'warnings', 'utf8' and 'version' are unnecessary or redundant};
20              
21             #-----------------------------------------------------------------------------
22              
23             my %map = (
24             v6 => 1,
25             constant => 1, # 'use constant FOO => 1' --> 'constant FOO = 1' later
26             base => 1, # 'use base "Foo::Mommy' --> 'class Foo is Foo::Mommy' later
27             parent => 1, # 'use parent "Foo::Mommy' --> 'class Foo is Foo::Mommy' later
28             );
29              
30             #-----------------------------------------------------------------------------
31              
32 40     40 0 1320 sub supported_parameters { return () }
33 28     28 1 105 sub default_severity { return $SEVERITY_HIGHEST }
34 25     25 1 84 sub default_themes { return qw(core bugs) }
35             sub applies_to {
36             return sub {
37             $_[1]->isa('PPI::Statement::Include') and
38             ( is_version_number($_[1]->child(2)) or
39             is_pragma($_[1]->child(2)) ) and
40 57 50 33 57   772 not exists $map{$_[1]->child(2)->content}
      66        
41             }
42 4     4 1 26 }
43              
44             #-----------------------------------------------------------------------------
45              
46             #
47             # 'use strict;' --> ''
48             # 'use warnings;' --> ''
49             # 'no strict;' --> ''
50             # 'no warnings;' --> ''
51             # 'use 5.6;' --> ''
52             # 'use v6;' --> 'use v6;'
53             # 'use constant;' --> 'use constant;'
54             #
55             sub transform {
56 0     0 0   my ($self, $elem, $doc) = @_;
57              
58 0           $elem->remove;
59              
60 0           return $self->transformation( $DESC, $EXPL, $elem );
61             }
62              
63             1;
64              
65             #-----------------------------------------------------------------------------
66              
67             __END__
68              
69             =pod
70              
71             =head1 NAME
72              
73             Perl::ToPerl6::Transformer::Pragma::FormatPragma - Remove unnecessary pragmas
74              
75              
76             =head1 AFFILIATION
77              
78             This Transformer is part of the core L<Perl::ToPerl6|Perl::ToPerl6>
79             distribution.
80              
81              
82             =head1 DESCRIPTION
83              
84             Removes uneeded Perl5 pragmas. More specifically, it removes all core pragmas except C<v6>, C<constant>, C<base> and C<parent>. The C<v6> pragma remains untouched, C<constant> will be transformed later into <constant FOO = 1>, C<base> and C<parent> are added to the class declaration:
85              
86             use strict; --> ''
87             no strict 'refs'; --> ''
88             use warnings; --> ''
89             use constant FOO => 1; --> use constant FOO => 1;
90             use base qw(Foo); --> use base qw(Foo);
91              
92             Transforms pragmas outside of comments, heredocs, strings and POD.
93              
94             The 'constant', 'base' and 'parent' pragmas are left untouched for later transformers, so that they can do their Perl6 things.
95              
96             =head1 CONFIGURATION
97              
98             This Transformer is not configurable except for the standard options.
99              
100             =head1 AUTHOR
101              
102             Jeffrey Goff <drforr@pobox.com>
103              
104             =head1 COPYRIGHT
105              
106             Copyright (c) 2015 Jeffrey Goff
107              
108             This program is free software; you can redistribute it and/or modify
109             it under the same terms as Perl itself.
110              
111             =cut
112              
113             ##############################################################################
114             # Local Variables:
115             # mode: cperl
116             # cperl-indent-level: 4
117             # fill-column: 78
118             # indent-tabs-mode: nil
119             # c-indentation-style: bsd
120             # End:
121             # ex: set ts=8 sts=4 sw=4 tw=78 ft=perl expandtab shiftround :