| 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
| |||||||||||||||
| 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
| |||||||||||||||
| 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
| |||||||||||||||
| 65 | 5 | ▶ | return if $elem->raw_type eq '%'; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 66 | |||||||||||||||
| 67 | 5 | ▶ | if ( $elem->next_sibling ) { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 68 | 4 | my $subscript = $elem->snext_sibling; | |||||||||||||
| 69 | 4 | ▶ | return unless $subscript->isa('PPI::Structure::Subscript'); | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 70 | 0 | my $new_content = $elem->content; | |||||||||||||
| 71 | |||||||||||||||
| 72 | 0 | ▶ | if ( $subscript->start eq '[' ) { | ||||||||||||
|
Branch: 2 branches
| |||||||||||||||
| 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__ | ||||||||||||||