« lib/Perl/ToPerl6/Transformer/BasicTypes/Rationals/AddTrailingZero.pm
↑ Summary
lib/Perl/ToPerl6/Transformer/Builtins/RewritePrint.pm »
| 1 | package Perl::ToPerl6::Transformer::CompoundStatements::AddWhitespace; | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | 17 | ▶ | use 5.006001; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 17 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | 17 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | 17 | ▶ | use Readonly; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||
| 8 | 17 | ▶ | use Perl::ToPerl6::Utils qw{ :severities }; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 9 | 17 | ▶ | use Perl::ToPerl6::Utils::PPI qw{ | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 10 | is_ppi_statement_compound | ||||||||||||||||||||||||||||
| 11 | is_ppi_token_word | ||||||||||||||||||||||||||||
| 12 | insert_trailing_whitespace | ||||||||||||||||||||||||||||
| 13 | 17 | }; | |||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||
| 15 | 17 | ▶ | use base 'Perl::ToPerl6::Transformer'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||
| 17 | #----------------------------------------------------------------------------- | ||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||
| 19 | 17 | Readonly::Scalar my $DESC => q{Transform 'if()' to 'if ()'}; | |||||||||||||||||||||||||||
| 20 | 17 | Readonly::Scalar my $EXPL => | |||||||||||||||||||||||||||
| 21 | q{if(), elsif() and unless() need whitespace in order to not be interpreted as function calls}; | ||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||
| 23 | #----------------------------------------------------------------------------- | ||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||
| 25 | 17 | my %map = ( | |||||||||||||||||||||||||||
| 26 | if => 1, | ||||||||||||||||||||||||||||
| 27 | elsif => 1, | ||||||||||||||||||||||||||||
| 28 | unless => 1, | ||||||||||||||||||||||||||||
| 29 | given => 1, | ||||||||||||||||||||||||||||
| 30 | when => 1, | ||||||||||||||||||||||||||||
| 31 | while => 1, | ||||||||||||||||||||||||||||
| 32 | until => 1, | ||||||||||||||||||||||||||||
| 33 | for => 1, | ||||||||||||||||||||||||||||
| 34 | foreach => 1, | ||||||||||||||||||||||||||||
| 35 | ); | ||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||
| 37 | #----------------------------------------------------------------------------- | ||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||
| 39 | 38 | ▶ | sub supported_parameters { return () } | ||||||||||||||||||||||||||
|
Subroutine
supported_parameters: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 40 | 27 | ▶ | sub default_necessity { return $NECESSITY_HIGHEST } | ||||||||||||||||||||||||||
|
Subroutine
default_necessity: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 41 | 24 | ▶ | sub default_themes { return qw( core ) } | ||||||||||||||||||||||||||
|
Subroutine
default_themes: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 42 | 5 | ▶ | sub applies_to { | ||||||||||||||||||||||||||
|
Subroutine
applies_to: called CC=1 SCAR=0.8
Pod
documented
| |||||||||||||||||||||||||||||
| 43 | 78 | ▶ | return sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=3 SCAR=14.2
| |||||||||||||||||||||||||||||
| 44 | 78 | ▶ | is_ppi_statement_compound($_[1], %map) or | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
is_ppi_statement_compound($_[1], %map) or $_[1]->isa("PPI::Statement::Given")
MC/DC0%0/2
is_ppi_statement_compound($_[1], %map) or $_[1]->isa("PPI::Statement::Given")
is_ppi_statement_compound($_[1], %map)
$_[1]->isa("PPI::Statement::Given")
Truth table33%1/3
A or B
A= is_ppi_statement_compound($_[1], %map)B= $_[1]->isa("PPI::Statement::Given")
| |||||||||||||||||||||||||||||
| 45 | $_[1]->isa('PPI::Statement::Given') or | ||||||||||||||||||||||||||||
| 46 | $_[1]->isa('PPI::Statement::When') | ||||||||||||||||||||||||||||
| 47 | } | ||||||||||||||||||||||||||||
| 48 | 5 | } | |||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||
| 50 | #----------------------------------------------------------------------------- | ||||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||
| 52 | # | ||||||||||||||||||||||||||||
| 53 | # Note to the reader: | ||||||||||||||||||||||||||||
| 54 | # | ||||||||||||||||||||||||||||
| 55 | # $elem (PPI::Statement::Compound) | ||||||||||||||||||||||||||||
| 56 | # \ | ||||||||||||||||||||||||||||
| 57 | # \ 0 1 2 3 4 # count by child() | ||||||||||||||||||||||||||||
| 58 | # \0 1 2 3 4 # count by schild() | ||||||||||||||||||||||||||||
| 59 | # +-----+-----+-----+-----+ | ||||||||||||||||||||||||||||
| 60 | # | | | | | | ||||||||||||||||||||||||||||
| 61 | # V V V V V | ||||||||||||||||||||||||||||
| 62 | # if (...) {...} elsif (...) | ||||||||||||||||||||||||||||
| 63 | # | ||||||||||||||||||||||||||||
| 64 | # After insertion, the tree looks like this: | ||||||||||||||||||||||||||||
| 65 | # | ||||||||||||||||||||||||||||
| 66 | # $elem (PPI::Statement::Compound) | ||||||||||||||||||||||||||||
| 67 | # \ | ||||||||||||||||||||||||||||
| 68 | # \ 0 1 2 3 4 5 6 # count by child() | ||||||||||||||||||||||||||||
| 69 | # \0 1 2 3 4 # count by schild() | ||||||||||||||||||||||||||||
| 70 | # +-----+-----+-----+-----+-----+----+ | ||||||||||||||||||||||||||||
| 71 | # | | | | | | | | ||||||||||||||||||||||||||||
| 72 | # V V V V V V V | ||||||||||||||||||||||||||||
| 73 | # if ' ' (...) {...} elsif ' ' (...) | ||||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||
| 75 | 0 | ▶ | sub transform { | ||||||||||||||||||||||||||
|
Subroutine
transform: not called CC=3 SCAR=24.8
Pod
undocumented
| |||||||||||||||||||||||||||||
| 76 | 0 | my ($self, $elem, $doc) = @_; | |||||||||||||||||||||||||||
| 77 | |||||||||||||||||||||||||||||
| 78 | 0 | for my $child ( $elem->schildren ) { | |||||||||||||||||||||||||||
| 79 | 0 | ▶ | next unless is_ppi_token_word($child, %map); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 80 | 0 | insert_trailing_whitespace($child); | |||||||||||||||||||||||||||
| 81 | } | ||||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||
| 83 | 0 | return $self->transformation( $DESC, $EXPL, $elem ); | |||||||||||||||||||||||||||
| 84 | } | ||||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||
| 86 | 17 | 1; | |||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||||
| 88 | #----------------------------------------------------------------------------- | ||||||||||||||||||||||||||||
| 89 | |||||||||||||||||||||||||||||
| 90 | __END__ | ||||||||||||||||||||||||||||