Commit | Line | Data |
3176feef |
1 | use strict; |
f9d19a00 |
2 | use warnings; |
3176feef |
3 | |
4 | use Test::More; |
5 | |
6 | BEGIN { |
b715d61b |
7 | plan skip_all => 'Perl 5.010 is required' unless "$]" >= '5.010'; |
82559400 |
8 | plan skip_all => 'Tests skipped on perl 5.27.{7,8,9} when smartmatch behaviour changed' if "$]" >= '5.027007' and "$]" < '5.027010'; |
c8e3a471 |
9 | plan skip_all => 'given/when have been removed in perl 5.42' if "$]" >= '5.041003'; |
c6d66f74 |
10 | plan tests => 5; |
3176feef |
11 | } |
12 | |
01b96275 |
13 | use Try::Tiny; |
3176feef |
14 | |
15 | use 5.010; |
8c34b0ef |
16 | no if "$]" >= 5.017011, warnings => 'experimental::smartmatch'; |
3176feef |
17 | |
18 | my ( $foo, $bar, $other ); |
19 | |
20 | $_ = "magic"; |
21 | |
22 | try { |
8d2ee831 |
23 | die "foo"; |
3176feef |
24 | } catch { |
25 | |
8d2ee831 |
26 | like( $_, qr/foo/ ); |
3176feef |
27 | |
8d2ee831 |
28 | when (/bar/) { $bar++ }; |
29 | when (/foo/) { $foo++ }; |
30 | default { $other++ }; |
3176feef |
31 | }; |
32 | |
33 | is( $_, "magic", '$_ not clobbered' ); |
34 | |
35 | ok( !$bar, "bar didn't match" ); |
36 | ok( $foo, "foo matched" ); |
37 | ok( !$other, "fallback didn't match" ); |