};
my $method = $code->new(sub {
$_->(@_) for @{$modifier_table->{before}};
- my @rval = $modifier_table->{around}->{cache}->(@_);
+ my (@rlist, $rval);
+ if (defined wantarray) {
+ if (wantarray) {
+ @rlist = $modifier_table->{around}->{cache}->(@_);
+ }
+ else {
+ $rval = $modifier_table->{around}->{cache}->(@_);
+ }
+ }
+ else {
+ $modifier_table->{around}->{cache}->(@_);
+ }
$_->(@_) for @{$modifier_table->{after}};
- return wantarray ? @rval : $rval[0];
+ return unless defined wantarray;
+ return wantarray ? @rlist : $rval;
});
$MODIFIERS{$method} = $modifier_table;
$method;
$wrapped->add_around_modifier(sub { (3, $_[0]->()) });
$wrapped->add_around_modifier(sub { (2, $_[0]->()) });
$wrapped->add_around_modifier(sub { (1, $_[0]->()) });
+ $wrapped->add_around_modifier(sub { (0, $_[0]->()) });
} '... added the around modifier okay';
is_deeply(
[ $wrapped->() ],
- [ 1, 2, 3, 4 ],
- '... got the right results back from the around methods');
+ [ 0, 1, 2, 3, 4 ],
+ '... got the right results back from the around methods (in list context)');
+
+ is(scalar $wrapped->(), 4, '... got the right results back from the around methods (in scalar context)');
}