Permalink
Browse files

Perlito5 - perl6 - my sub

  • Loading branch information...
1 parent 68a48a3 commit 890d83b462c6f33ae47cd11f727a22c62b281371 @fglock committed Oct 15, 2013
Showing with 18 additions and 3 deletions.
  1. +9 −1 perlito5.pl
  2. +9 −2 src5/lib/Perlito5/Perl6/Emitter.pm
View
10 perlito5.pl
@@ -12811,12 +12811,20 @@ package Perlito5::AST::Sub;
if defined($self->{'block'});
return(['op' => 'prefix:<sub>', @parts])
if !$self->{'name'};
+ my $is_our = 1;
+ $is_our = 0
+ if $self->{'decl'} eq 'my';
my $name = $self->{'name'};
if ($Perlito5::PKG_NAME ne $self->{'namespace'}) {
$name = $self->{'namespace'} . '::' . $name;
+ $is_our = 0
+ }
+ if ($is_our) {
+ return(['stmt' => ['keyword' => 'our'], ['keyword' => 'sub'], ['bareword' => $name], @parts])
+ }
+ else {
return(['stmt' => ['keyword' => 'sub'], ['bareword' => $name], @parts])
}
- return(['stmt' => ['keyword' => 'our'], ['keyword' => 'sub'], ['bareword' => $name], @parts])
}
}
package Perlito5::AST::Do;
View
11 src5/lib/Perlito5/Perl6/Emitter.pm
@@ -678,14 +678,21 @@ package Perlito5::AST::Sub;
if defined $self->{block};
return [ op => 'prefix:<sub>', @parts ] if !$self->{name};
- # TODO - 'my' subroutines
+ my $is_our = 1; # our is default in perl5
+ $is_our = 0 if $self->{decl} eq 'my';
my $name = $self->{name};
if ( $Perlito5::PKG_NAME ne $self->{namespace} ) {
$name = $self->{namespace} . "::" . $name;
+ $is_our = 0;
+ }
+
+ if ($is_our) {
+ return [ stmt => [ keyword => 'our' ], [ keyword => 'sub' ], [ bareword => $name ], @parts ];
+ }
+ else {
return [ stmt => [ keyword => 'sub' ], [ bareword => $name ], @parts ];
}
- return [ stmt => [ keyword => 'our' ], [ keyword => 'sub' ], [ bareword => $name ], @parts ];
}
}

0 comments on commit 890d83b

Please sign in to comment.