From: Robin Edwards Date: Sun, 11 Apr 2010 22:51:11 +0000 (+0100) Subject: started syntax changes X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=74c60aceefc744286da2091509aefd31a2a96a61;p=p5sagit%2FDevel-Declare-Keyword.git started syntax changes --- diff --git a/examples/Methods.pm b/examples/Methods.pm index 3c3c9f2..c381877 100644 --- a/examples/Methods.pm +++ b/examples/Methods.pm @@ -3,7 +3,7 @@ use lib 'lib/'; use Devel::Declare::Keyword qw/debug/; use Data::Dumper; -keyword method (ident?, proto?, block) { +keyword method (Maybe[ident] $ident, Maybe[proto] $proto, Block $block) { $block->name($ident); $block->inject_begin($proto); $block->inject_after("warn 'post block inject ok';"); diff --git a/lib/Devel/Declare/Keyword.pm b/lib/Devel/Declare/Keyword.pm index 1deb6ad..613133a 100644 --- a/lib/Devel/Declare/Keyword.pm +++ b/lib/Devel/Declare/Keyword.pm @@ -12,7 +12,7 @@ use Devel::Declare::Keyword::Parse::Block; use Devel::Declare::Keyword::Parse::Proto 'parse_proto'; use Devel::Declare::Keyword::Parse::Ident 'parse_ident'; -our $VERSION = '0.03'; +our $VERSION = '0.04'; our $KW_MODULE = caller; our $DEBUG = 0; @@ -136,17 +136,30 @@ sub eos { }; } +# parse keywords prototype and return code sub kw_proto_to_code { my ($proto) = @_; - my $inject = " my ("; + + my @var; - $proto =~ s/\?//g; - $proto =~ s/\s//g; - $proto =~ s/\,/\,\$/g; - $proto = "\$".$proto if length $proto; - $inject .= $proto.') = @_; '; + my $parse_rule; - return $inject; + for my $item (split /,/, $proto) { + my ($decl,$name) = split /\s/, $item; + if ($decl =~ /Maybe\[(\w+)\]/) { + $parse_rule = $1; + } + elsif($decl =~ /\w+/) { + $parse_rule = $1; + } + else { + confess "error parsing keyword prototype"; + } + push @var, $name; + } + + warn " my (".join(', $', @var).') = @_;'; + return " my (".join(', $', @var).') = @_;'; } # build import routine for new keyword module