- fix tests failing on 5.6.x due to differing DESTROY semantics
- excise superfluous local($@) call - 7% speedup
- fix (fsvo) broken URLs (RT#55659)
+ - proper exception on erroneous usage of bare catch/finally (RT#81070)
+ - proper exception on erroneous use of multiple catch{} blocks
0.12
- doc fixes
my $ref = ref($code_ref);
if ( $ref eq 'Try::Tiny::Catch' ) {
+ croak 'A try() may not be followed by multiple catch() blocks'
+ if $catch;
$catch = ${$code_ref};
} elsif ( $ref eq 'Try::Tiny::Finally' ) {
push @finally, ${$code_ref};
sub catch (&;@) {
my ( $block, @rest ) = @_;
+ croak 'Useless bare catch()' unless defined wantarray;
+
return (
bless(\$block, 'Try::Tiny::Catch'),
@rest,
sub finally (&;@) {
my ( $block, @rest ) = @_;
+ croak 'Useless bare finally()' unless defined wantarray;
+
return (
bless(\$block, 'Try::Tiny::Finally'),
@rest,
--- /dev/null
+#!/usr/bin/perl
+
+use strict;
+use warnings;
+
+use Test::More tests => 5;
+use Try::Tiny;
+
+sub _eval {
+ local $@;
+ local $Test::Builder::Level = $Test::Builder::Level + 2;
+ return ( scalar(eval { $_[0]->(); 1 }), $@ );
+}
+
+sub throws_ok (&$$) {
+ my ( $code, $regex, $desc ) = @_;
+ local $Test::Builder::Level = $Test::Builder::Level + 1;
+
+ my ( $ok, $error ) = _eval($code);
+
+ if ( $ok ) {
+ fail($desc);
+ } else {
+ like($error || '', $regex, $desc );
+ }
+}
+
+throws_ok {
+ try { 1 }; catch { 2 };
+} qr/\QUseless bare catch()/, 'Bare catch() detected';
+
+throws_ok {
+ try { 1 }; finally { 2 };
+} qr/\QUseless bare finally()/, 'Bare finally() detected';
+
+throws_ok {
+ try { 1 }; catch { 2 } finally { 2 };
+} qr/\QUseless bare catch()/, 'Bare catch()/finally() detected';
+
+throws_ok {
+ try { 1 }; finally { 2 } catch { 2 };
+} qr/\QUseless bare finally()/, 'Bare finally()/catch() detected';
+
+
+throws_ok {
+ try { 1 } catch { 2 } catch { 3 } finally { 4 } finally { 5 }
+} qr/\QA try() may not be followed by multiple catch() blocks/, 'Multi-catch detected';
+