File Coverage

blib/lib/Perl/ToPerl6/Transformer/Arrays/FormatArrayQws.pm
Criterion Covered Total %
statement 25 30 83.3
branch n/a
condition n/a
subroutine 12 13 92.3
pod 3 5 60.0
total 40 48 83.3


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