prefer Sub::Util to Sub::Name
[p5sagit/Try-Tiny.git] / t / named.t
1 #!/usr/bin/perl
2
3 use strict;
4 use warnings;
5
6 use Test::More;
7
8 BEGIN {
9     plan skip_all => "Sub::Util or Sub::Name required"
10         unless eval { require Sub::Util; defined &Sub::Util::set_subname; }
11             || eval { require Sub::Name; Sub::Name->VERSION(0.08) };
12     plan tests => 3;
13 }
14
15 use Try::Tiny;
16
17 my $name;
18 try {
19     $name = (caller(0))[3];
20 };
21 is $name, "main::try {...} ", "try name"; # note extra space
22
23 try {
24     die "Boom";
25 } catch {
26     $name = (caller(0))[3];
27 };
28 is $name, "main::catch {...} ", "catch name"; # note extra space
29
30 try {
31     die "Boom";
32 } catch {
33     # noop
34 } finally {
35     $name = (caller(0))[3];
36 };
37 is $name, "main::finally {...} ", "finally name"; # note extra space
38