From: Robin Edwards Date: Fri, 11 Dec 2009 13:17:56 +0000 (+0000) Subject: change begin accessor to code removed end accessor X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=f10168c8367eef483b501788257c842ad9c9650a;p=p5sagit%2FDevel-Declare-Keyword.git change begin accessor to code removed end accessor --- diff --git a/lib/Keyword/Parse/Block.pm b/lib/Keyword/Parse/Block.pm index b4c8114..9106897 100644 --- a/lib/Keyword/Parse/Block.pm +++ b/lib/Keyword/Parse/Block.pm @@ -1,6 +1,9 @@ package Keyword::Parse::Block; use strict; use warnings; +use B::Hooks::EndOfScope; + +#doesnt actualy 'parse' a block, just detects the start. sub new { my ($parser) = @_; @@ -16,34 +19,48 @@ sub match { } } -#add end of scope hook #inject code -sub begin { +sub code { my ($self, $code) = @_; + $self->{eos} =$self->{parser}->package."::_". + $self->{name}."_inject_scope"; + + #add end of scope hook + $code = " BEGIN { $self->{eos}()}; $code"; + + no strict 'refs'; + *{$self->{eos}} = sub {}; + my $l = $self->{parser}->line; substr($l, $self->{parser}->offset+1, 0) = $code; $self->{parser}->skip_ws; + #added end of scope hook $self->{parser}->line($l); } sub name { my ($self, $name) = @_; no strict 'refs'; + $self->{name} = $name; $self->{parser}->shadow($name); } + +#set end of scope code +# !! B:H:EOS won't allow you to inject code into the block sub terminate { - my $self = shift - # remove need for semi colon - #*{$module_user."::inject_scope"} = sub { - # on_scope_end { - # my $l = $parser->line; - # my $loffset = $parser->line_offset; - # substr($l, $loffset, 0) = ';'; - # $parser->line($l); - # }; - #} + my ($self) = @_; + no strict 'refs'; + no warnings 'redefine'; + *{$self->{eos}} = sub { + on_scope_end { + my $l = $self->{parser}->line; + my $loffset = $self->{parser}->line_offset; + substr($l, $loffset, 0) = ';'; + $self->{parser}->line($l); + }; + }; } 1; diff --git a/lib/Keyword/Parser.pm b/lib/Keyword/Parser.pm index 6d5cdbb..b8c1328 100644 --- a/lib/Keyword/Parser.pm +++ b/lib/Keyword/Parser.pm @@ -61,6 +61,8 @@ sub package { } sub line_offset { + my ($self, $os) = @_; + Devel::Declare::set_linestr_offset($os) if $os; return Devel::Declare::get_linestr_offset; }