1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39
|
use strict;
use warnings;
use Test::More;
use TryCatch;
my $last_context;
sub fun {
my ($should_die) = @_;
try {
die 1 if $should_die;
$last_context = wantarray;
}
catch ($e where { /^1/ }) {
$last_context = wantarray;
}
}
my @v;
$v[0] = fun();
is($last_context, '', "Scalar try context preserved");
@v = fun();
is($last_context, 1, "Array try context preserved");
fun();
is($last_context, undef, "void try context preserved");
$v[0] = fun(1);
is($last_context, '', "Scalar catch context preserved");
@v = fun(1);
is($last_context, 1, "Array catch context preserved");
fun(1);
is($last_context, undef, "void catch context preserved");
done_testing;
|