File Coverage

blib/lib/Perl/ToPerl6/Transformer/Variables/ReplaceUndef.pm
Criterion Covered Total %
statement 26 37 70.2
branch 0 8 0.0
condition 0 27 0.0
subroutine 13 14 92.8
pod 3 6 50.0
total 42 92 45.6


line stmt bran cond sub pod time code
1             package Perl::ToPerl6::Transformer::Variables::ReplaceUndef;
2              
3 17     17   10911 use 5.006001;
  17         49  
4 17     17   72 use strict;
  17         22  
  17         374  
5 17     17   178 use warnings;
  17         19  
  17         392  
6 17     17   62 use Readonly;
  17         24  
  17         794  
7              
8 17     17   78 use Perl::ToPerl6::Utils qw{ :characters :severities };
  17         27  
  17         865  
9 17     17   4126 use Perl::ToPerl6::Utils::PPI qw{ is_ppi_token_word };
  17         30  
  17         850  
10              
11 17     17   86 use base 'Perl::ToPerl6::Transformer';
  17         27  
  17         7066  
12              
13             our $VERSION = '0.03';
14              
15             #-----------------------------------------------------------------------------
16              
17             Readonly::Scalar my $DESC =>
18             q{'undef' no longer exists, 'Any' is a reasonable approximation};
19             Readonly::Scalar my $EXPL =>
20             q{'undef' no longer exists, 'Any' is a reasonable approximation};
21              
22             #-----------------------------------------------------------------------------
23              
24             my %map = (
25             undef => 1
26             );
27              
28             #-----------------------------------------------------------------------------
29              
30 33     33 0 106 sub run_after { return 'Operators::FormatOperators' }
31 41     41 0 1310 sub supported_parameters { return () }
32 29     29 1 120 sub default_severity { return $SEVERITY_HIGHEST }
33 25     25 1 78 sub default_themes { return qw(core bugs) }
34             sub applies_to {
35             return sub {
36 65     65   772 is_ppi_token_word($_[1], %map)
37             }
38 4     4 1 20 }
39              
40             #-----------------------------------------------------------------------------
41              
42             sub transform {
43 0     0 0   my ($self, $elem, $doc) = @_;
44              
45 0 0 0       if ( $elem->snext_sibling and
    0 0        
      0        
      0        
      0        
      0        
      0        
46             $elem->snext_sibling->isa('PPI::Token::Symbol') and
47             $elem->snext_sibling->snext_sibling and
48             $elem->snext_sibling->snext_sibling->isa('PPI::Token::Operator') and
49             $elem->snext_sibling->snext_sibling->content eq '->' ) {
50 0           $elem->snext_sibling->snext_sibling->snext_sibling->insert_after(
51             PPI::Token::Word->new(':delete')
52             );
53 0           $elem->snext_sibling->snext_sibling->set_content('.');
54 0 0 0       $elem->next_sibling->delete if
55             $elem->next_sibling and
56             $elem->next_sibling->isa('PPI::Token::Whitespace');
57 0           $elem->remove;
58             }
59             elsif ( $elem->snext_sibling and
60             $elem->snext_sibling->isa('PPI::Token::Symbol') and
61             $elem->snext_sibling->snext_sibling and
62             $elem->snext_sibling->snext_sibling->isa('PPI::Structure::Subscript') ) {
63 0           $elem->snext_sibling->snext_sibling->insert_after(
64             PPI::Token::Word->new(':delete')
65             );
66 0 0 0       $elem->next_sibling->delete if
67             $elem->next_sibling and
68             $elem->next_sibling->isa('PPI::Token::Whitespace');
69 0           $elem->remove;
70             }
71             else {
72 0           $elem->set_content('Any');
73             }
74              
75 0           return $self->transformation( $DESC, $EXPL, $elem );
76             }
77              
78             1;
79              
80             #-----------------------------------------------------------------------------
81              
82             __END__
83              
84             =pod
85              
86             =head1 NAME
87              
88             Perl::ToPerl6::Transformer::Variables::FormatSigils - Give variables their proper sigils.
89              
90              
91             =head1 AFFILIATION
92              
93             This Transformer is part of the core L<Perl::ToPerl6|Perl::ToPerl6>
94             distribution.
95              
96              
97             =head1 DESCRIPTION
98              
99             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:
100              
101             @foo = () --> @foo = ()
102             $foo[1] --> @foo[1]
103             %foo = () --> %foo = ()
104             $foo{a} --> %foo{a} # Not %foo<a> or %foo{'a'} yet.
105              
106             Transforms variables outside of comments, heredocs, strings and POD.
107              
108             =head1 CONFIGURATION
109              
110             This Transformer is not configurable except for the standard options.
111              
112             =head1 AUTHOR
113              
114             Jeffrey Goff <drforr@pobox.com>
115              
116             =head1 COPYRIGHT
117              
118             Copyright (c) 2015 Jeffrey Goff
119              
120             This program is free software; you can redistribute it and/or modify
121             it under the same terms as Perl itself.
122              
123             =cut
124              
125             ##############################################################################
126             # Local Variables:
127             # mode: cperl
128             # cperl-indent-level: 4
129             # fill-column: 78
130             # indent-tabs-mode: nil
131             # c-indentation-style: bsd
132             # End:
133             # ex: set ts=8 sts=4 sw=4 tw=78 ft=perl expandtab shiftround :