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

filter: Statementstmt 69.5% 32 / 46 Branchbran 43.7% 7 / 16 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 11 / 11 Podpod 60.0% 3 / 5 totaltotal 67.9% 53 / 78 CC 9 SCAR 25.9
CC
9
Cov
63%
transform
27.0
BEGIN
1.0
BEGIN
1.0
CRAP 13.3
« lib/Test/Perl/ToPerl6/Transformer.pm ↑ Summary lib/Perl/ToPerl6/Utils.pm »
1 package Perl::ToPerl6::Transformer::Variables::RewriteSigils;
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  
10 17 ▶use base 'Perl::ToPerl6::Transformer';
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 #-----------------------------------------------------------------------------
13  
14 17 Readonly::Scalar my $DESC => q{Transform $x[0] to @x[0]};
15 17 Readonly::Scalar my $EXPL =>
16 q{Perl6 uses the data type as the sigil now, not the context desired};
17  
18 #-----------------------------------------------------------------------------
19  
20 38 ▶sub supported_parameters { return () }
Subroutine supported_parameters: called CC=1 SCAR=0.0
Pod undocumented
21 28 ▶sub default_necessity { return $NECESSITY_HIGHEST }
Subroutine default_necessity: called CC=1 SCAR=0.0
Pod documented
22 24 ▶sub default_themes { return qw( core ) }
Subroutine default_themes: called CC=1 SCAR=0.0
Pod documented
23 5 ▶sub applies_to {
Subroutine applies_to: called CC=1 SCAR=0.0
Pod documented
24 5 return 'PPI::Token::Symbol',
25 'PPI::Token::ArrayIndex'
26 }
27  
28 #-----------------------------------------------------------------------------
29  
30 #
31 # %foo --> %foo
32 # $foo{a} --> %foo{a} # Note it does not pointify braces.
33 # @foo --> @foo
34 # $foo[1] --> @foo[1]
35 #
36 6 ▶sub transform {
Subroutine transform: called CC=9 SCAR=32.9
Pod undocumented
37 6 my ($self, $elem, $doc) = @_;
38 6 ▶ if ( $elem->isa('PPI::Token::ArrayIndex') ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($elem->isa('PPI::Token::ArrayIndex')) { } 0 6 6
39 0 my $content = $elem->content;
40  
41 0 $content =~ s{\$#}{};
42  
43 #
44 # There's a bug that causes $elem->parent to go away here.
45 # Not sure if it's PPI or not...
46 #
47 0 ▶unless ( $elem->parent ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($elem->parent) 0 0 0
48 0 warn "XXX PPI bug triggered\n";
49 0 return;
50 }
51  
52 $elem->insert_before(
53 0 PPI::Token::Symbol->new('@' . $content)
54 );
55 0 $elem->insert_before(
56 PPI::Token::Symbol->new('.')
57 );
58 0 $elem->insert_before(
59 PPI::Token::Word->new('end')
60 );
61 0 $elem->delete;
62 }
63 else {
64 6 ▶ return if $elem->raw_type eq '@';
Branch: 1 branch
BranchTrueFalseTotal
if $elem->raw_type eq "\@" 1 5 6
65 5 ▶ return if $elem->raw_type eq '%';
Branch: 1 branch
BranchTrueFalseTotal
if $elem->raw_type eq "%" 0 5 5
66  
67 5 ▶ if ( $elem->next_sibling ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($elem->next_sibling) 4 1 5
68 4 my $subscript = $elem->snext_sibling;
69 4 ▶ return unless $subscript->isa('PPI::Structure::Subscript');
Branch: 1 branch
BranchTrueFalseTotal
unless $subscript->isa("PPI::Structure::Subscript") 4 0 4
70 0 my $new_content = $elem->content;
71  
72 0 ▶ if ( $subscript->start eq '[' ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($subscript->start eq '[') { } 0 0 0
elsif ($subscript->start eq '{') { } 0 0 0
73 0 substr($new_content, 0, 1) = '@';
74 }
75 elsif ( $subscript->start eq '{' ) {
76 0 substr($new_content, 0, 1) = '%';
77 }
78 0 $elem->set_content( $new_content );
79 }
80 }
81  
82 1 return $self->transformation( $DESC, $EXPL, $elem );
83 }
84  
85 17 1;
86  
87 #-----------------------------------------------------------------------------
88  
89 __END__
« lib/Test/Perl/ToPerl6/Transformer.pm ↑ Summary lib/Perl/ToPerl6/Utils.pm »