Changes for Devel-Declare
+ - stop using & prototypes at all
+
0.001004
- correct idiotic typo if ifndef
use warnings;
use 5.008001;
-our $VERSION = '0.001003';
+our $VERSION = '0.001004';
# mirrored in Declare.xs as DD_HANDLE_*
package ${pack};
my \$body;
sub ${name} (${proto}) :lvalue {\n"
- .'my $ret = $body->(@_);
+ .' if (wantarray) {
+ my @ret = $body->(@_);
+ return @ret;
+ }
+ my $ret = $body->(@_);
return $ret;
};
sub { ($body) = @_; };';
$sub_proto =~ s/;//; $sub_proto = ';'.$sub_proto;
#my $installer = $class->build_sub_installer($pack, $name, $proto);
my $installer = $class->build_sub_installer($pack, $name, '@');
- my $proto_maker = eval q!
- sub {
- my $body = shift;
- sub (!.$sub_proto.q!) {
- $body->(@_);
- };
- };
- !;
$installer->(sub :lvalue {
+#{ no warnings 'uninitialized'; warn 'INST: '.join(', ', @_)."\n"; }
if (@_) {
if (ref $_[0] eq 'HASH') {
shift;
+ if (wantarray) {
+ my @ret = $run->(undef, undef, @_);
+ return @ret;
+ }
my $r = $run->(undef, undef, @_);
return $r;
} else {
- return $_[1];
+ return @_[1..$#_];
}
}
return my $sv;
sub {
my ($usepack, $use, $inpack, $name, $proto) = @_;
my $extra_code = $compile->($name, $proto);
- my $main_handler = $proto_maker->(sub {
+ my $shift_hashref = defined(wantarray);
+ my $main_handler = sub { shift if $shift_hashref;
("DONE", $run->($name, $proto, @_));
- });
+ };
my ($name_h, $XX);
if (defined $proto) {
$name_h = sub :lvalue { return my $sv; };
$XX = $main_handler;
} elsif (defined $name && length $name) {
$name_h = $main_handler;
- } else {
- $extra_code ||= '';
- $extra_code = '}, sub {'.$extra_code;
}
+ $extra_code ||= '';
+ $extra_code = '}, sub {'.$extra_code;
return ($name_h, $XX, $extra_code);
}
];
'DeclareTest', 'method', DECLARE_PACKAGE | DECLARE_PROTO,
sub {
my ($name, $proto) = @_;
+no warnings 'uninitialized';
+warn "NP: ".join(', ', @_)."\n";
return 'my $self = shift;' unless defined $proto && $proto ne '@_';
return 'my ($self'.(length $proto ? ", ${proto}" : "").') = @_;';
},
sub {
- my ($name, $proto, $sub) = @_;
+ my ($name, $proto, $sub, @rest) = @_;
+no warnings 'uninitialized';
+warn "NPS: ".join(', ', @_)."\n";
if (defined $name && length $name) {
unless ($name =~ /::/) {
$name = "DeclareTest::${name}";
no strict 'refs';
*{$name} = $sub;
}
- return $sub;
+ return wantarray ? ($sub, @rest) : $sub;
}
);
}
-my ($test_method1, $test_method2);
+my ($test_method1, $test_method2, @test_list);
{
package DeclareTest;
return join(', ', ref $self, $what);
};
+ @test_list = method { 1 }, sub { 2 }, method () { 3 }, sub { 4 };
+
}
use Test::More 'no_plan';
is($o->$test_method1('no', 'yes'), 'value, yes', 'anon method with @_ ok');
is($o->$test_method2('this'), 'DeclareTest2, this', 'anon method with proto ok');
+
+warn map { $_->() } @test_list;