lib/Perl/ToPerl6/Transformer/Variables/ReplaceNegativeIndex.pm

filter: Statementstmt 91.8% 34 / 37 Branchbran 50.0% 5 / 10 Conditioncond 60.0% 9 / 15 MC/DCmcdc 37.5% 3 / 8 Subroutinesub 100% 14 / 14 Podpod 50.0% 3 / 6 totaltotal 75.5% 68 / 90 CC 10 SCAR 18.6
CC
10
Cov
77%
transform
17.1
__ANON__
4.0
applies_to
1.0
CRAP 6.4
« lib/Perl/ToPerl6/TransformerFactory.pm ↑ Summary lib/Perl/ToPerl6/UserProfile.pm »
1 package Perl::ToPerl6::Transformer::Variables::ReplaceNegativeIndex;
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{ is_ppi_token_word };
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 17 ▶use base 'Perl::ToPerl6::Transformer';
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13 #-----------------------------------------------------------------------------
14  
15 17 Readonly::Scalar my $DESC => q{Negative array indexes now need [*-1] notation};
16 17 Readonly::Scalar my $EXPL => q{Negative array indexes now need [*-1] notation};
17  
18 #-----------------------------------------------------------------------------
19  
20 #
21 # That way we don't have to deal with the integer conversions.
22 #
23 31 ▶sub run_before {
Subroutine run_before: called CC=1 SCAR=0.0
Pod undocumented
24 31 return 'BasicTypes::Integers::RewriteBinaryNumbers',
25 'BasicTypes::Integers::RewriteOctalNumbers',
26 'BasicTypes::Integers::RewriteHexNumbers'
27 }
28  
29 38 ▶sub supported_parameters { return () }
Subroutine supported_parameters: called CC=1 SCAR=0.0
Pod undocumented
30 28 ▶sub default_necessity { return $NECESSITY_HIGHEST }
Subroutine default_necessity: called CC=1 SCAR=0.0
Pod documented
31 24 ▶sub default_themes { return qw( core ) }
Subroutine default_themes: called CC=1 SCAR=0.0
Pod documented
32 #
33 # Don't test the subscript type because the [-N] may be after a {}.
34 #
35 5 ▶sub applies_to {
Subroutine applies_to: called CC=1 SCAR=0.0
Pod documented
36 78 ▶ return sub {
Subroutine __ANON__: called CC=4 SCAR=13.9
37 78 ▶ $_[1]->isa('PPI::Token::Symbol') and
Branch: 1 branch
BranchTrueFalseTotal
$_[1]->isa("PPI::Token::Symbol") and $_[1]->snext_sibling and $_[1]->snext_sibling->isa("PPI::Structure::Subscript") || $_[1]->snext_sibling->isa("PPI::Token::Operator") 5 73 78
Condition88%8/9
$_[1]->isa('PPI::Token::Symbol') && $_[1]->snext_sibling && ($_[1]->snext_sibling->isa('PPI::Structure::Subscript') || $_[1]->snext_sibling->isa('PPI::Token::Operator'))
!ll&&!rl&&r
7341
$_[1]->isa("PPI::Token::Symbol") and $_[1]->snext_sibling
!ll&&!rl&&r
7215
$_[1]->snext_sibling->isa("PPI::Structure::Subscript") or $_[1]->snext_sibling->isa("PPI::Token::Operator")
l!l&&r!l&&!r
014
MC/DC75%3/4
$_[1]->isa('PPI::Token::Symbol') && $_[1]->snext_sibling && ($_[1]->snext_sibling->isa('PPI::Structure::Subscript') || $_[1]->snext_sibling->isa('PPI::Token::Operator'))
$_[1]->isa("PPI::Token::Symbol") $_[1]->snext_sibling $_[1]->snext_sibling->isa("PPI::Structure::Subscript") $_[1]->snext_sibling->isa("PPI::Token::Operator")
Truth table80%4/5
A and B && C or D
A= $_[1]->isa("PPI::Token::Symbol")B= $_[1]->snext_siblingC= $_[1]->snext_sibling->isa("PPI::Structure::Subscript")D= $_[1]->snext_sibling->isa("PPI::Token::Operator")
ABCDresult
0XXX0
10XX0
11000
111X1
11011
38 $_[1]->snext_sibling and
39 ( $_[1]->snext_sibling->isa('PPI::Structure::Subscript') or
40 $_[1]->snext_sibling->isa('PPI::Token::Operator') )
41 }
42 5 }
43  
44 #-----------------------------------------------------------------------------
45  
46 1 ▶sub transform {
Subroutine transform: called CC=7 SCAR=28.4
Pod undocumented
47 1 my ($self, $elem, $doc) = @_;
48 1 my $head = $elem;
49  
50 1 ▶ while ( $head = $head->snext_sibling ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($head = $head->snext_sibling) 5 1 6
51 5 ▶ next unless $head->isa('PPI::Structure::Subscript') and
Branch: 1 branch
BranchTrueFalseTotal
unless $head->isa("PPI::Structure::Subscript") and $head->start eq "[" 5 0 5
Condition33%1/3
$head->isa("PPI::Structure::Subscript") and $head->start eq "["
!ll&&!rl&&r
500
MC/DC0%0/2
$head->isa("PPI::Structure::Subscript") and $head->start eq "["
$head->isa("PPI::Structure::Subscript") $head->start eq "["
Truth table33%1/3
A and B
A= $head->isa("PPI::Structure::Subscript")B= $head->start eq "["
ABresult
0X0
100
111
52 $head->start eq '[';
53 0 ▶ if ( $head->schild(0)->isa('PPI::Statement::Expression') ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($head->schild(0)->isa("PPI::Statement::Expression")) 0 0 0
54 0 ▶ if ( $head->schild(0)->schild(0)->isa('PPI::Token::Number') and
Branch: 1 branch
BranchTrueFalseTotal
if ($head->schild(0)->schild(0)->isa("PPI::Token::Number") and $head->schild(0)->schild(0)->content =~ /^ [-] /x) 0 0 0
Condition0%0/3
$head->schild(0)->schild(0)->isa("PPI::Token::Number") and $head->schild(0)->schild(0)->content =~ /^ [-] /x
!ll&&!rl&&r
000
MC/DC0%0/2
$head->schild(0)->schild(0)->isa("PPI::Token::Number") and $head->schild(0)->schild(0)->content =~ /^ [-] /x
$head->schild(0)->schild(0)->isa("PPI::Token::Number") $head->schild(0)->schild(0)->content =~ /^ [-] /x
Truth table0%0/3
A and B
A= $head->schild(0)->schild(0)->isa("PPI::Token::Number")B= $head->schild(0)->schild(0)->content =~ /^ [-] /x
ABresult
0X0
100
111
55 $head->schild(0)->schild(0)->content =~ /^ [-] /x ) {
56 #
57 # Don't use the operator '*' lest it get confused. This way
58 # the code is still syntactically correct.
59 #
60 0 $head->schild(0)->schild(0)->insert_before(
61 PPI::Token::Word->new('*')
62 );
63 }
64 }
65 }
66  
67 1 return $self->transformation( $DESC, $EXPL, $elem );
68 }
69  
70 17 1;
71  
72 #-----------------------------------------------------------------------------
73  
74 __END__
« lib/Perl/ToPerl6/TransformerFactory.pm ↑ Summary lib/Perl/ToPerl6/UserProfile.pm »