File Coverage

blib/lib/Perl/ToPerl6/Transformer/BasicTypes/Strings/AddWhitespace.pm
Criterion Covered Total %
statement 22 27 81.4
branch 1 2 50.0
condition 2 3 66.6
subroutine 11 12 91.6
pod 3 5 60.0
total 39 49 79.5


line stmt bran cond sub pod time code
1             package Perl::ToPerl6::Transformer::BasicTypes::Strings::AddWhitespace;
2              
3 17     17   11123 use 5.006001;
  17         54  
4 17     17   76 use strict;
  17         25  
  17         346  
5 17     17   64 use warnings;
  17         23  
  17         363  
6 17     17   60 use Readonly;
  17         24  
  17         836  
7              
8 17     17   91 use Perl::ToPerl6::Utils qw{ :characters :severities };
  17         24  
  17         931  
9              
10 17     17   4333 use base 'Perl::ToPerl6::Transformer';
  17         34  
  17         5416  
11              
12             our $VERSION = '0.03';
13              
14             #-----------------------------------------------------------------------------
15              
16             Readonly::Scalar my $DESC => q{Rewrite interpolated strings};
17             Readonly::Scalar my $EXPL => q{Rewrite interpolated strings};
18              
19             #-----------------------------------------------------------------------------
20              
21 40     40 0 1853 sub supported_parameters { return () }
22 29     29 1 111 sub default_severity { return $SEVERITY_HIGHEST }
23 25     25 1 90 sub default_themes { return qw(core bugs) }
24             sub applies_to {
25             return sub {
26             $_[1]->isa('PPI::Token::Quote') and
27             $_[1]->{operator} and
28 61 50 66 61   772 $_[1]->{operator} =~ / ^ q /x
29             }
30 4     4 1 19 }
31              
32             #-----------------------------------------------------------------------------
33              
34             sub transform {
35 0     0 0   my ($self, $elem, $doc) = @_;
36              
37 0           my $new_content = $elem->content;
38              
39 0           $new_content =~ s{ ^ (q?q)[(] }{$1 (}x;
40              
41 0           $elem->set_content( $new_content );
42              
43 0           return $self->transformation( $DESC, $EXPL, $elem );
44             }
45              
46             1;
47              
48             #-----------------------------------------------------------------------------
49              
50             __END__
51              
52             =pod
53              
54             =head1 NAME
55              
56             Perl::ToPerl6::Transformer::BasicTypes::Strings::AddWhitespace - Add whitespace between q/qq and ()
57              
58              
59             =head1 AFFILIATION
60              
61             This Transformer is part of the core L<Perl::ToPerl6|Perl::ToPerl6>
62             distribution.
63              
64              
65             =head1 DESCRIPTION
66              
67             Perl6 q() and qq() delimiters require whitespace if you're using round braces,
68             otherwise they get confused with a q() or qq() function:
69              
70             q(Hello world) --> q (Hello world)
71             q[Hello world] --> q[Hello world]
72             qq (Hello world) --> q (Hello world)
73             qq[Hello world] --> qq[Hello world]
74              
75             Transforms only interpolated strings outside of comments, heredocs and POD.
76              
77             =head1 CONFIGURATION
78              
79             This Transformer is not configurable except for the standard options.
80              
81             =head1 AUTHOR
82              
83             Jeffrey Goff <drforr@pobox.com>
84              
85             =head1 COPYRIGHT
86              
87             Copyright (c) 2015 Jeffrey Goff
88              
89             This program is free software; you can redistribute it and/or modify
90             it under the same terms as Perl itself.
91              
92             =cut
93              
94             ##############################################################################
95             # Local Variables:
96             # mode: cperl
97             # cperl-indent-level: 4
98             # fill-column: 78
99             # indent-tabs-mode: nil
100             # c-indentation-style: bsd
101             # End:
102             # ex: set ts=8 sts=4 sw=4 tw=78 ft=perl expandtab shiftround :