From: Matt S Trout Date: Mon, 17 Sep 2007 01:10:55 +0000 (+0000) Subject: made method { ... }; work X-Git-Tag: 0.005000~130 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=c55344969531eb7450247484b1e99504d1046f43;p=p5sagit%2FDevel-Declare.git made method { ... }; work --- diff --git a/lib/Devel/Declare.pm b/lib/Devel/Declare.pm index 8d0f5a5..e334045 100644 --- a/lib/Devel/Declare.pm +++ b/lib/Devel/Declare.pm @@ -151,8 +151,14 @@ sub setup_declarators { }; !; $installer->(sub :lvalue { - if (@_) { warn @_; - $run->(undef, undef, @_); + if (@_) { + if (ref $_[0] eq 'HASH') { + shift; + my $r = $run->(undef, undef, @_); + return $r; + } else { + return $_[1]; + } } return my $sv; }); @@ -162,14 +168,17 @@ sub setup_declarators { my ($usepack, $use, $inpack, $name, $proto) = @_; my $extra_code = $compile->($name, $proto); my $main_handler = $proto_maker->(sub { - $run->($name, $proto, @_); + ("DONE", $run->($name, $proto, @_)); }); my ($name_h, $XX); if (defined $proto) { $name_h = sub :lvalue { return my $sv; }; $XX = $main_handler; - } else { + } elsif (defined $name && length $name) { $name_h = $main_handler; + } else { + $extra_code ||= ''; + $extra_code = '}, sub {'.$extra_code; } return ($name_h, $XX, $extra_code); } diff --git a/t/sugar.t b/t/sugar.t index e71a944..4ca64e6 100644 --- a/t/sugar.t +++ b/t/sugar.t @@ -46,7 +46,7 @@ my ($test_method1, $test_method2); return 'DeclareTest2: bar'; }; - $test_method1 = method (@_) { + $test_method1 = method { return join(', ', $self->{attr}, $_[1]); };