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