« lib/Perl/ToPerl6/Theme.pm
↑ Summary
lib/Perl/ToPerl6/Exception/Configuration/Option/Global/ParameterValue.pm »
| 1 | package Perl::ToPerl6::Transformer::CompoundStatements::SwapForArguments; | ||||||||||||||||||||||||||||||||||||||||||
| 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 | insert_trailing_whitespace | ||||||||||||||||||||||||||||||||||||||||||
| 12 | remove_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 | 31 | ▶ | sub run_after { return 'Operators::FormatOperators' } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
run_after: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 26 | 38 | ▶ | sub supported_parameters { return () } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
supported_parameters: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 27 | 27 | ▶ | sub default_necessity { return $NECESSITY_HIGHEST } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
default_necessity: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 28 | 24 | ▶ | sub default_themes { return qw( core ) } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
default_themes: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||||||||||||||||
| 30 | #----------------------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||||||||||||||||
| 32 | 17 | my %map = ( | |||||||||||||||||||||||||||||||||||||||||
| 33 | for => 1, | ||||||||||||||||||||||||||||||||||||||||||
| 34 | foreach => 1, | ||||||||||||||||||||||||||||||||||||||||||
| 35 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||||||||||||||||
| 37 | 17 | my %scope_map = ( | |||||||||||||||||||||||||||||||||||||||||
| 38 | my => 1, | ||||||||||||||||||||||||||||||||||||||||||
| 39 | local => 1, | ||||||||||||||||||||||||||||||||||||||||||
| 40 | our => 1 | ||||||||||||||||||||||||||||||||||||||||||
| 41 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||||||||||||||||
| 43 | 5 | ▶ | sub applies_to { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
applies_to: called CC=1 SCAR=2.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 44 | 90 | ▶ | return sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=3 SCAR=17.3
| |||||||||||||||||||||||||||||||||||||||||||
| 45 | 90 | ▶ | is_ppi_statement_compound($_[1], %map) and | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition16%1/6
is_ppi_statement_compound($_[1], %map) && ($_[1]->schild(1)->isa('PPI::Token::Word') || $_[1]->schild(1)->isa('PPI::Token::Symbol'))
$_[1]->schild(1)->isa("PPI::Token::Word") or $_[1]->schild(1)->isa("PPI::Token::Symbol")
MC/DC0%0/3
is_ppi_statement_compound($_[1], %map) && ($_[1]->schild(1)->isa('PPI::Token::Word') || $_[1]->schild(1)->isa('PPI::Token::Symbol'))
is_ppi_statement_compound($_[1], %map)
$_[1]->schild(1)->isa("PPI::Token::Word")
$_[1]->schild(1)->isa("PPI::Token::Symbol")
Truth table25%1/4
A && B or C
A= is_ppi_statement_compound($_[1], %map)B= $_[1]->schild(1)->isa("PPI::Token::Word")C= $_[1]->schild(1)->isa("PPI::Token::Symbol")
| |||||||||||||||||||||||||||||||||||||||||||
| 46 | ( $_[1]->schild(1)->isa('PPI::Token::Word') or | ||||||||||||||||||||||||||||||||||||||||||
| 47 | $_[1]->schild(1)->isa('PPI::Token::Symbol') ) | ||||||||||||||||||||||||||||||||||||||||||
| 48 | } | ||||||||||||||||||||||||||||||||||||||||||
| 49 | 5 | } | |||||||||||||||||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||||||||||||||||
| 51 | #----------------------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||||||||||||||||
| 53 | 0 | ▶ | sub transform { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
transform: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 54 | 0 | my ($self, $elem, $doc) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||||||||||||||||
| 56 | # This ASCII art may be of use. | ||||||||||||||||||||||||||||||||||||||||||
| 57 | # | ||||||||||||||||||||||||||||||||||||||||||
| 58 | # $elem $loop_variable | ||||||||||||||||||||||||||||||||||||||||||
| 59 | # | | | ||||||||||||||||||||||||||||||||||||||||||
| 60 | # | | $whitespace | ||||||||||||||||||||||||||||||||||||||||||
| 61 | # | | | | ||||||||||||||||||||||||||||||||||||||||||
| 62 | # [ q{for}, q{ }, q{my}, q{ }, q{$x}, q{ }, q{(@x)} ] | ||||||||||||||||||||||||||||||||||||||||||
| 63 | # | | | | | | | | ||||||||||||||||||||||||||||||||||||||||||
| 64 | # | | X X | | | | ||||||||||||||||||||||||||||||||||||||||||
| 65 | # | | | | | | ||||||||||||||||||||||||||||||||||||||||||
| 66 | # | | ,-----------' | | | ||||||||||||||||||||||||||||||||||||||||||
| 67 | # | | | ,------------' | | ||||||||||||||||||||||||||||||||||||||||||
| 68 | # | | | | ,------------' | ||||||||||||||||||||||||||||||||||||||||||
| 69 | # | | | | | | ||||||||||||||||||||||||||||||||||||||||||
| 70 | # V | V V V | ||||||||||||||||||||||||||||||||||||||||||
| 71 | # [ q{for}, q{ }, q{$x}, q{ }, q{(@x)} ] | ||||||||||||||||||||||||||||||||||||||||||
| 72 | # | | | | | | ||||||||||||||||||||||||||||||||||||||||||
| 73 | # | | '------|-----|--------------, | ||||||||||||||||||||||||||||||||||||||||||
| 74 | # | `-------------, | | | ||||||||||||||||||||||||||||||||||||||||||
| 75 | # | | | | | | ||||||||||||||||||||||||||||||||||||||||||
| 76 | # | ,------------' | | | | ||||||||||||||||||||||||||||||||||||||||||
| 77 | # | | .-------|---' | | ||||||||||||||||||||||||||||||||||||||||||
| 78 | # | | | | | | ||||||||||||||||||||||||||||||||||||||||||
| 79 | # | | | | + + | | ||||||||||||||||||||||||||||||||||||||||||
| 80 | # V V V | | | V | ||||||||||||||||||||||||||||||||||||||||||
| 81 | # [ q{for}, q{ }, q{(@x)}, q{ }, q{->}, q{ }, q{$x} ] | ||||||||||||||||||||||||||||||||||||||||||
| 82 | # | ||||||||||||||||||||||||||||||||||||||||||
| 83 | 0 | ▶ | if ( $scope_map{$elem->schild(1)->content} ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 84 | 0 | remove_trailing_whitespace($elem->schild(1)); | |||||||||||||||||||||||||||||||||||||||||
| 85 | 0 | $elem->schild(1)->delete; | |||||||||||||||||||||||||||||||||||||||||
| 86 | } | ||||||||||||||||||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||||||||||||||||||
| 88 | 0 | my $whitespace = remove_trailing_whitespace($elem->schild(1)); | |||||||||||||||||||||||||||||||||||||||||
| 89 | 0 | my $loop_variable = $elem->schild(1)->clone; | |||||||||||||||||||||||||||||||||||||||||
| 90 | 0 | $elem->schild(1)->remove; | |||||||||||||||||||||||||||||||||||||||||
| 91 | |||||||||||||||||||||||||||||||||||||||||||
| 92 | 0 | $elem->schild(1)->insert_after( | |||||||||||||||||||||||||||||||||||||||||
| 93 | $loop_variable | ||||||||||||||||||||||||||||||||||||||||||
| 94 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 95 | 0 | insert_trailing_whitespace($elem->schild(1)); | |||||||||||||||||||||||||||||||||||||||||
| 96 | 0 | $elem->schild(1)->insert_after( | |||||||||||||||||||||||||||||||||||||||||
| 97 | PPI::Token::Operator->new('->') | ||||||||||||||||||||||||||||||||||||||||||
| 98 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 99 | 0 | insert_trailing_whitespace($elem->schild(1)); | |||||||||||||||||||||||||||||||||||||||||
| 100 | |||||||||||||||||||||||||||||||||||||||||||
| 101 | 0 | return $self->transformation( $DESC, $EXPL, $elem ); | |||||||||||||||||||||||||||||||||||||||||
| 102 | } | ||||||||||||||||||||||||||||||||||||||||||
| 103 | |||||||||||||||||||||||||||||||||||||||||||
| 104 | 17 | 1; | |||||||||||||||||||||||||||||||||||||||||
| 105 | |||||||||||||||||||||||||||||||||||||||||||
| 106 | #----------------------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||||||||||
| 107 | |||||||||||||||||||||||||||||||||||||||||||
| 108 | __END__ | ||||||||||||||||||||||||||||||||||||||||||