From: Robin Edwards Date: Fri, 11 Dec 2009 19:44:18 +0000 (+0000) Subject: finished parse syntax X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=d8e74e633b2139a627f4c5e9110a151e2e175d2c;p=p5sagit%2FDevel-Declare-Keyword.git finished parse syntax --- diff --git a/lib/Keyword.pm b/lib/Keyword.pm index 9fd23b3..7fbb907 100644 --- a/lib/Keyword.pm +++ b/lib/Keyword.pm @@ -23,11 +23,11 @@ sub import { ); no strict 'refs'; - *{$KW_MODULE.'::parse'} = sub (&) {}; *{$KW_MODULE.'::keyword'} = sub (&) { no strict 'refs'; $Keyword::__keyword_block = shift; }; + *{$KW_MODULE.'::parse'} = sub (&) { }; strict->import; warnings->import; @@ -65,7 +65,7 @@ sub keyword_parser { $parser->line($l); #install shadow for keyword routine - $parser->shadow($keyword); + $parser->shadow($parser->package."::".$keyword); } # parses the parse keyword @@ -89,8 +89,11 @@ sub parse_parser { substr($l, $parser->offset+1, 0) = $code; $parser->line($l); - #install shadow for keyword routine - $parser->shadow($name); + no strict 'refs'; + no warnings 'redefine'; + *{$KW_MODULE.'::parse'} = sub (&) { + *{$parser->package."::parse_$name"} = shift; + }; } sub eos { diff --git a/lib/Keyword/Parse/Block.pm b/lib/Keyword/Parse/Block.pm index 9106897..1e3acc1 100644 --- a/lib/Keyword/Parse/Block.pm +++ b/lib/Keyword/Parse/Block.pm @@ -42,6 +42,7 @@ sub code { sub name { my ($self, $name) = @_; no strict 'refs'; + $name = $self->{parser}->package."::$name" if $name; $self->{name} = $name; $self->{parser}->shadow($name); } diff --git a/lib/Keyword/Parser.pm b/lib/Keyword/Parser.pm index b8c1328..09e1a3c 100644 --- a/lib/Keyword/Parser.pm +++ b/lib/Keyword/Parser.pm @@ -67,25 +67,24 @@ sub line_offset { } sub shadow { - my ($self, $name) = @_; - $name = $self->package()."::$name" if $name; - my $sub; + my ($self, $name, $sub) = @_; #set name as global for import; no strict 'refs'; ${$self->package."::__block_name"} = $name; - - if($name) { - $sub = sub (&) { - no strict 'refs'; - *{$name} = shift; - }; - } - else { - $sub = sub (&) { ${$self->package."::__tmp_block"}; }; + + unless ($sub) { + if($name) { + $sub = sub (&) { + *{$name} = shift; + }; + } + else { + $sub = sub (&) { shift; }; + } } - Devel::Declare::shadow_sub("$name", $sub); + Devel::Declare::shadow_sub($name, $sub); } 1; diff --git a/t/02-syntax.t b/t/02-syntax.t index f1202a1..b96e218 100644 --- a/t/02-syntax.t +++ b/t/02-syntax.t @@ -8,8 +8,11 @@ keyword method (ident?, proto?, thing, block) { } parse thing ($parser) { - warn Dumper $parser; + ok 1; + ok 1 if !defined $parser; } +parse_thing(); + ok 1;