#parse an action routines called for each entry in proto
keyword method (ident?, proto?, custom, block) {
$block->name($ident); # name the block
- $block->code($proto); # inject proto code (at begining)
+ $block->inject_begin($proto); # inject at begin of block
+ $block->inject_after("warn '$ident() finished';");
$block->terminate; # add semi colon
}
keyword method (ident?, proto?, block) {
$block->name($ident);
- $block->code($proto);
+ $block->inject_begin($proto);
+ $block->inject_after("warn 'HELLO!';");
$block->terminate;
}
keyword method (ident?, proto?, block) {
$block->name($ident); # assign the block to subroutine
- $block->code($proto); # inject proto code
+ $block->inject_begin($proto); # inject proto code
+ $block->inject_after("warn '$ident() finished';");
$block->terminate; # add semi colon
}
use strict;
use warnings;
use B::Hooks::EndOfScope;
+use Data::Dumper;
#doesnt actualy 'parse' a block, just detects the start.
}
}
-#inject code
-sub code {
+
+sub inject_before {
+ my ($self,$code) = @_;
+}
+
+sub code { inject_begin(@_); };
+
+#inject code into start of block
+sub inject_begin {
my ($self, $code) = @_;
+ $code =~ s/\n/\ /g;
+
$self->{eos} =$self->{parser}->package."::_".
$self->{name}."_inject_scope";
$self->{parser}->line($l);
}
+#injects code after the end of the block
+sub inject_after {
+ my ($self, $code) = @_;
+ $code =~ s/\n/\ /g;
+ $self->{inject_after} = $code;
+
+}
+
sub name {
my ($self, $name) = @_;
no strict 'refs';
on_scope_end {
my $l = $self->{parser}->line;
my $loffset = $self->{parser}->line_offset;
- substr($l, $loffset, 0) = ';';
+ substr($l, $loffset, 0) = '; '.
+ ($self->{inject_after}?$self->{inject_after}:"");
$self->{parser}->line($l);
};
};