From: Geoffrey T. Dairiki Date: Wed, 5 Aug 2009 00:54:34 +0000 (-0700) Subject: overload no longer implicitly unsets fallback on repeated 'use overload' lines -... X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=c989e6a3e4b89b26d315693449c76cdcb754611f;p=p5sagit%2Fp5-mst-13.2.git overload no longer implicitly unsets fallback on repeated 'use overload' lines - Fix for RT#68916 Subject: overload::import resets the setting of 'fallback' Date: Tue, 04 Aug 2009 17:54:34 -0700 From: "Geoffrey T. Dairiki" --- diff --git a/MANIFEST b/MANIFEST index 861bdc8..5c69043 100644 --- a/MANIFEST +++ b/MANIFEST @@ -4224,6 +4224,7 @@ t/lib/locale/utf8 Part of locale.t in UTF8 t/lib/mypragma.pm An example user pragma t/lib/mypragma.t Test the example user pragma t/lib/no_load.t Test that some modules don't load others +t/lib/overload_fallback.t Test that using overload 2x in a scope doesn't clobber fallback t/lib/proxy_constant_subs.t Test that Proxy Constant Subs behave correctly t/lib/Sans_mypragma.pm Test module for t/lib/mypragma.t t/lib/strict/refs Tests of "use strict 'refs'" for strict.t diff --git a/lib/overload.pm b/lib/overload.pm index d5ac5ad..fffff6e 100644 --- a/lib/overload.pm +++ b/lib/overload.pm @@ -9,6 +9,7 @@ sub OVERLOAD { my %arg = @_; my ($sub, $fb); $ {$package . "::OVERLOAD"}{dummy}++; # Register with magic by touching. + $fb = ${$package . "::()"}; # preserve old fallback value RT#68196 *{$package . "::()"} = \&nil; # Make it findable via fetchmethod. for (keys %arg) { if ($_ eq 'fallback') { diff --git a/t/lib/overload_fallback.t b/t/lib/overload_fallback.t new file mode 100644 index 0000000..6b50042 --- /dev/null +++ b/t/lib/overload_fallback.t @@ -0,0 +1,18 @@ +use warnings; +use strict; +use Test::Simple tests => 2; + +use overload '""' => sub { 'stringvalue' }, fallback => 1; + +BEGIN { +my $x = bless {}, 'main'; +ok ($x eq 'stringvalue', 'fallback worked'); +} + + +# NOTE: delete the next line and this test script will pass +use overload '+' => sub { die "unused"; }; + +my $x = bless {}, 'main'; +ok (eval {$x eq 'stringvalue'}, 'fallback worked again'); +