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 40 41 42 43 44 45 46
|
#!/usr/bin/perl
use v5.14;
use warnings;
use Test2::V0;
use Syntax::Keyword::Try;
sub inner
{
my $canary = Canary->new; # if this line is commented, nothing happens
try {
return 123;
}
catch ($e) {
die "Something terrible happened: $e";
}
}
sub outer
{
my @result;
try {
@result = (1, scalar inner()); # scalar or void context is mandatory
1; # or catch will be triggered
}
catch ($e) {
die "Something terrible happened: $e";
}
return @result;
}
is [ outer() ], [ 1, 123 ], "No extra data in return";
done_testing;
package Canary;
sub new {
bless {}, shift;
}
sub DESTROY {
my $x; # Destructor MUST be nonempty
$@ = "oops"; # Assigning to $@ is optional
}
|