Skip to content

Commit

Permalink
Merge pull request Dual-Life#57 from schwern/bug/exceptions-overload-…
Browse files Browse the repository at this point in the history
…fallback

Allow checking for exception equality and string comparisons.
  • Loading branch information
nthykier committed Nov 25, 2014
2 parents 5c2c6f9 + 04a7ca5 commit 5d82a67
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
9 changes: 4 additions & 5 deletions lib/autodie/exception.pm
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,12 @@ use Carp qw(croak);
our $DEBUG = 0;

use overload
q{""} => "stringify"
q{""} => "stringify",
# Overload smart-match only if we're using 5.10 or up
($] >= 5.010 ? ('~~' => "matches") : ()),
fallback => 1
;

# Overload smart-match only if we're using 5.10

use if ($] >= 5.010), overload => '~~' => "matches";

my $PACKAGE = __PACKAGE__; # Useful to have a scalar for hash keys.

=head1 NAME
Expand Down
2 changes: 2 additions & 0 deletions t/exceptions.t
Original file line number Diff line number Diff line change
Expand Up @@ -44,3 +44,5 @@ ok($@ ~~ ':file', "Exception from close / class :file" );
ok($@ ~~ ':io', "Exception from close / class :io" );
ok($@ ~~ ':all', "Exception from close / class :all" );

ok $@ eq $@.'', "string overloading is complete (eq)";
ok( ($@ cmp $@.'') == 0, "string overloading is complete (cmp)" );

0 comments on commit 5d82a67

Please sign in to comment.