use Data::Dumper;
keyword method (ident?, proto?, block) {
- warn "method params: ".Dumper @_;
# $block->begin("warn 'hello from me';");
$block->name($ident);
};
$KW_MODULE,
{ keyword => { const => \&sig_parser } }
);
+
no strict 'refs';
*{$KW_MODULE.'::keyword'} = sub (&) {
no strict 'refs';
#parses keyword signature
sub sig_parser {
+
+
my $parser = Keyword::Parser->new;
$parser->next_token;
$parser->skip_ws;
substr($l, $parser->offset+1, 0) = proto_to_code($proto);
$parser->line($l);
- #construct shadow sub
- my $shadow = sub (&) { no strict 'refs'; *{$KW_MODULE."::$keyword"} = shift };
-
#install shadow for keyword routine
- $parser->shadow($keyword, $shadow);
+ $parser->shadow($keyword);
}
sub proto_to_code {
my ($pb, $keyword) = @_;
return sub {
- # module_user is the user of your Keyword based module
my $module_user = caller();
+
+ # module_user is the user of your Keyword based module
Devel::Declare->setup_for(
$module_user,
{ $keyword => { const => $pb } }
# setup prototype for there keyword into modules namespace
no strict 'refs';
- *{$module_user."::$keyword"} = sub (&) {};
+ *{$module_user."::$keyword"} = sub (&) {
+ no strict 'refs';
+ my $name = ${$module_user."::__block_name"};
+ *{$name} = shift; #store block
+ ${$module_user."::__block_name"} = undef;
+ };
};
}
sub shadow {
my ($self, $name) = @_;
$name = $self->package()."::$name" if $name;
-
my $sub;
+ #set name as global for import;
+ no strict 'refs';
+ ${$self->package."::__block_name"} = $name;
+
if($name) {
-
- warn "$name: ".Dumper @_;
$sub = sub (&) {
no strict 'refs';
*{$name} = shift;
};
}
else {
- $sub = sub (&) { shift; };
+ $sub = sub (&) { ${$self->package."::__tmp_block"}; };
}
Devel::Declare::shadow_sub("$name", $sub);