From: matthewt Date: Mon, 17 Sep 2007 01:10:55 +0000 (+0000) Subject: made method { ... }; work X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=5880ed9075a8416b9a7cc98aa2e3ca928b67be5b;p=p5sagit%2FDevel-Declare.git made method { ... }; work git-svn-id: http://dev.catalyst.perl.org/repos/bast/trunk/Devel-Declare@3753 bd8105ee-0ff8-0310-8827-fb3f25b6796d --- 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]); };