only invoke caller() when _HAS_SUBNAME
[p5sagit/Try-Tiny.git] / t / when.t
1 use strict;
2 use warnings;
3
4 use Test::More;
5
6 BEGIN {
7   plan skip_all => 'Perl 5.010 is required' unless "$]" >= '5.010';
8   plan tests => 5;
9 }
10
11 use Try::Tiny;
12
13 use 5.010;
14 no if "$]" >= 5.017011, warnings => 'experimental::smartmatch';
15
16 my ( $foo, $bar, $other );
17
18 $_ = "magic";
19
20 try {
21   die "foo";
22 } catch {
23
24   like( $_, qr/foo/ );
25
26   when (/bar/) { $bar++ };
27   when (/foo/) { $foo++ };
28   default { $other++ };
29 };
30
31 is( $_, "magic", '$_ not clobbered' );
32
33 ok( !$bar, "bar didn't match" );
34 ok( $foo, "foo matched" );
35 ok( !$other, "fallback didn't match" );