"Modernize" code a bit
[p5sagit/Try-Tiny.git] / t / given_when.t
CommitLineData
1a2992bb 1#!/usr/bin/perl
2
3use strict;
4use warnings;
5
6use Test::More;
7
8BEGIN {
8d2ee831 9 plan skip_all => "Perl 5.10 is required" unless eval { require 5.010 };
10 plan tests => 3;
11 use_ok("Try::Tiny");
1a2992bb 12}
13
73664e25 14use 5.010;
f9d19a00 15no if $] >= 5.017011, warnings => 'experimental::smartmatch';
73664e25 16
1a2992bb 17my ( $error, $topic );
18
19given ("foo") {
8d2ee831 20 when (qr/./) {
21 try {
22 die "blah\n";
23 } catch {
24 $topic = $_;
25 $error = $_[0];
26 }
27 };
1a2992bb 28}
29
30is( $error, "blah\n", "error caught" );
31
32{
8d2ee831 33 local $TODO = "perhaps a workaround can be found";
34 is( $topic, $error, 'error is also in $_' );
1a2992bb 35}
36
1a2992bb 37# ex: set sw=4 et:
38