File Coverage

blib/lib/Perl/ToPerl6/Transformer/BasicTypes/Strings/RenameRegex.pm
Criterion Covered Total %
statement 20 27 74.0
branch n/a
condition n/a
subroutine 9 12 75.0
pod 3 6 50.0
total 32 45 71.1


line stmt bran cond sub pod time code
1             package Perl::ToPerl6::Transformer::BasicTypes::Strings::RenameRegex;
2              
3 1     1   739 use 5.006001;
  1         4  
4 1     1   4 use strict;
  1         1  
  1         18  
5 1     1   5 use warnings;
  1         1  
  1         20  
6 1     1   4 use Readonly;
  1         2  
  1         45  
7              
8 1     1   5 use Perl::ToPerl6::Utils qw{ :severities };
  1         2  
  1         46  
9              
10 1     1   121 use base 'Perl::ToPerl6::Transformer';
  1         2  
  1         232  
11              
12             #-----------------------------------------------------------------------------
13              
14             Readonly::Scalar my $DESC => q{qr{...} is now rx{...} - Does not alter the contents of qr{...}};
15             Readonly::Scalar my $EXPL =>
16             q{qr{...} is now written as rx{...} - The contents are not rewritten};
17              
18             #-----------------------------------------------------------------------------
19              
20 1     1 0 3 sub run_after { return 'BasicTypes::Strings::AddWhitespace' }
21 1     1 0 5 sub supported_parameters { return () }
22 1     1 1 4 sub default_necessity { return $NECESSITY_HIGHEST }
23 0     0 1   sub default_themes { return qw( core ) }
24 0     0 1   sub applies_to { return 'PPI::Token::QuoteLike::Regexp' }
25              
26             #-----------------------------------------------------------------------------
27              
28             #
29             # Note to the reader:
30             #
31             # A PPI::Token::QuoteLike::Regexp object contains a single string which has the
32             # entire 'qr{...}' token. Therefore we can't add a Token::Whitespace between
33             # the 'qr' and '{..}' like we can with loops and conditionals.
34             #
35              
36             sub transform {
37 0     0 0   my ($self, $elem, $doc) = @_;
38              
39 0           my $content = $elem->content;
40              
41 0           $content =~ s{^qr}{rx};
42              
43 0           $elem->set_content( $content );
44              
45 0           return $self->transformation( $DESC, $EXPL, $elem );
46             }
47              
48             1;
49              
50             #-----------------------------------------------------------------------------
51              
52             __END__
53              
54             =pod
55              
56             =head1 NAME
57              
58             Perl::ToPerl6::Transformer::BasicTypes::Strings::RenameRegex - Format regexps correctly
59              
60              
61             =head1 AFFILIATION
62              
63             This Transformer is part of the core L<Perl::ToPerl6|Perl::ToPerl6>
64             distribution.
65              
66              
67             =head1 DESCRIPTION
68              
69             Perl6 regexps now use rx{}
70              
71             qr{} --> rx{}
72              
73             Transforms qr{} outside of comments, heredocs, strings and POD.
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 :