File Coverage

blib/lib/Perl/ToPerl6/Transformer/Arrays/AddWhitespace.pm
Criterion Covered Total %
statement 22 30 73.3
branch n/a
condition n/a
subroutine 9 13 69.2
pod 3 5 60.0
total 34 48 70.8


line stmt bran cond sub pod time code
1             package Perl::ToPerl6::Transformer::Arrays::AddWhitespace;
2              
3 1     1   720 use 5.006001;
  1         3  
4 1     1   5 use strict;
  1         2  
  1         18  
5 1     1   5 use warnings;
  1         1  
  1         27  
6 1     1   5 use Readonly;
  1         2  
  1         40  
7              
8 1     1   6 use Perl::ToPerl6::Utils qw{ :severities };
  1         1  
  1         56  
9 1     1   111 use Perl::ToPerl6::Utils::PPI qw{ is_ppi_token_quotelike_words_like };
  1         2  
  1         39  
10              
11 1     1   4 use base 'Perl::ToPerl6::Transformer';
  1         2  
  1         319  
12              
13             #-----------------------------------------------------------------------------
14              
15             Readonly::Scalar my $DESC => q{Transform qw(...) to qw (...)};
16             Readonly::Scalar my $EXPL =>
17             q{qw<>, qw{} &c are fine, but qw() is now a function call. Add ' ' to avoid this};
18              
19             #-----------------------------------------------------------------------------
20              
21 2     2 0 6 sub supported_parameters { return () }
22 1     1 1 6 sub default_necessity { return $NECESSITY_HIGHEST }
23 0     0 1   sub default_themes { return qw(core bugs) }
24             sub applies_to {
25             return sub {
26 0     0     is_ppi_token_quotelike_words_like($_[1],qr{^qw\(})
27             }
28 0     0 1   }
29              
30             #-----------------------------------------------------------------------------
31             #
32             # Note to the reader:
33             #
34             # A PPI::Token::QuoteLike::Words object contains a single string which has the
35             # entire 'qw{...}' token. Therefore we can't add a Token::Whitespace between
36             # the 'qw' and '{..}' like we can with loops and conditionals.
37             #
38             sub transform {
39 0     0 0   my ($self, $elem, $doc) = @_;
40 0           my $old_content = $elem->content;
41              
42 0           $old_content =~ s< ^ qw\( ><qw (>x;
43              
44 0           $elem->set_content( $old_content );
45              
46 0           return $self->transformation( $DESC, $EXPL, $elem );
47             }
48              
49             1;
50              
51             #-----------------------------------------------------------------------------
52              
53             __END__
54              
55             =pod
56              
57             =head1 NAME
58              
59             Perl::ToPerl6::Transformer::Array::AddWhitespace - Format qw() to qw ()
60              
61              
62             =head1 AFFILIATION
63              
64             This Transformer is part of the core L<Perl::ToPerl6|Perl::ToPerl6> distribution.
65              
66              
67             =head1 DESCRIPTION
68              
69             Perl6 qw() operates almost exactly like Perl5 qw() but with one corner case - C<qw(a b c)>, like any bareword followed by an open parenthesis, is treated as a function call. This Transformer places a whitespace between C<qw> and C<(...)> in order to disambiguate, like so:
70              
71             qw(a b c) --> qw (a b c)
72             qw{a b c} --> qw{a b c}
73             qw<a b c> --> qw{a b c}
74              
75             =head1 CONFIGURATION
76              
77             This Transformer is not configurable except for the standard options.
78              
79             =head1 AUTHOR
80              
81             Jeffrey Goff <drforr@pobox.com>
82              
83             =head1 COPYRIGHT
84              
85             Copyright (c) 2015 Jeffrey Goff
86              
87             This program is free software; you can redistribute it and/or modify
88             it under the same terms as Perl itself.
89              
90             =cut
91              
92             ##############################################################################
93             # Local Variables:
94             # mode: cperl
95             # cperl-indent-level: 4
96             # fill-column: 78
97             # indent-tabs-mode: nil
98             # c-indentation-style: bsd
99             # End:
100             # ex: set ts=8 sts=4 sw=4 tw=78 ft=perl expandtab shiftround :