From: Robin Edwards Date: Fri, 11 Dec 2009 13:30:21 +0000 (+0000) Subject: prototype now works X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=d5c5b73cbb89893e2869f2bb38a486a83b52c98f;p=p5sagit%2FDevel-Declare-Keyword.git prototype now works --- diff --git a/examples/Methods.pm b/examples/Methods.pm index 8297d0f..162ee1b 100644 --- a/examples/Methods.pm +++ b/examples/Methods.pm @@ -5,16 +5,17 @@ use Data::Dumper; keyword method (ident?, proto?, block) { $block->name($ident); - $block->code("warn 'hello from Methods';"); + $block->code($proto); $block->terminate; } -sub action_ident { - return @_; -} +sub action_ident { shift; } # return method name sub action_proto { - return @_; + my $proto = shift; + $proto =~ s/\s//g; + $proto = "\$self,$proto" if length($proto); + return " my ($proto) = \@_; "; } 1; diff --git a/t/03-methods.t b/t/03-methods.t index 3bc78d7..e936a75 100644 --- a/t/03-methods.t +++ b/t/03-methods.t @@ -4,8 +4,8 @@ use warnings; use lib 'examples/'; use Methods; -method something ($a, $b, $c) { - return 1; +method add ($a, $b, $c) { + return $a+$b+$c; } @@ -14,6 +14,6 @@ method something ($a, $b, $c) { use Test::More qw/no_plan/; use Data::Dumper; -ok (Foobar->something); +ok (Foobar->add(1,2,3)==6); ok 1;