File: 90rt125971.t

package info (click to toggle)
libsyntax-keyword-try-perl 0.31-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 264 kB
  • sloc: perl: 898; makefile: 3
file content (46 lines) | stat: -rw-r--r-- 742 bytes parent folder | download | duplicates (2)
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
}