File Coverage

blib/lib/Perl/ToPerl6/Transformer/Variables/ReplaceUndef.pm
Criterion Covered Total %
statement 23 37 62.1
branch 0 4 0.0
condition 0 21 0.0
subroutine 10 14 71.4
pod 3 6 50.0
total 36 82 43.9


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