diff options
author | Jesse Luehrs <doy@tozt.net> | 2012-06-29 01:56:27 -0500 |
---|---|---|
committer | Jesse Luehrs <doy@tozt.net> | 2012-06-29 01:57:44 -0500 |
commit | 79c9643d871bd6cb08b3dd32a05ba534f13b890a (patch) | |
tree | b35790f56f3d66b880934d09faa3679498aa7f22 /lib/overload.t | |
parent | 56185adc32a821236821be07b37118f048b8bdad (diff) | |
download | perl-79c9643d871bd6cb08b3dd32a05ba534f13b890a.tar.gz |
fix 386a548 for fallback => undef
The default case for non-overloaded classes is fallback => 1, so saying
fallback => 1 on its own shouldn't enable overloading, but saying
fallback => undef on its own should (even though undef is the default
for overloaded classes).
Diffstat (limited to 'lib/overload.t')
-rw-r--r-- | lib/overload.t | 41 |
1 files changed, 35 insertions, 6 deletions
diff --git a/lib/overload.t b/lib/overload.t index 5212083b8b..597c1f7d24 100644 --- a/lib/overload.t +++ b/lib/overload.t @@ -48,7 +48,7 @@ package main; $| = 1; BEGIN { require './test.pl' } -plan tests => 5186; +plan tests => 5190; use Scalar::Util qw(tainted); @@ -2633,11 +2633,40 @@ is eval {"$a"}, overload::StrVal($a), 'fallback is stored under "()"'; package OnlyFallback; use overload fallback => 0; } - my $obj = bless {}, 'OnlyFallback'; - my $died = !eval { "".$obj; 1 }; - my $err = $@; - ok($died, "fallback of 0 causes error"); - like($err, qr/"\.": no method found/, "correct error"); + { + my $obj = bless {}, 'OnlyFallback'; + my $died = !eval { "".$obj; 1 }; + my $err = $@; + ok($died, "fallback of 0 causes error"); + like($err, qr/"\.": no method found/, "correct error"); + } + + { + package OnlyFallbackUndef; + use overload fallback => undef; + } + { + my $obj = bless {}, 'OnlyFallbackUndef'; + my $died = !eval { "".$obj; 1 }; + my $err = $@; + ok($died, "fallback of undef causes error"); + # this one tries falling back to stringify before dying + like($err, qr/"""": no method found/, "correct error"); + } + + { + package OnlyFallbackTrue; + use overload fallback => 1; + } + { + my $obj = bless {}, 'OnlyFallbackTrue'; + my $val; + my $died = !eval { $val = "".$obj; 1 }; + my $err = $@; + ok(!$died, "fallback of 1 doesn't cause error") + || diag("got error of $err"); + like($val, qr/^OnlyFallbackTrue=HASH\(/, "stringified correctly"); + } } { # undefining the overload stash -- KEEP THIS TEST LAST |