diff options
author | Father Chrysostomos <sprout@cpan.org> | 2012-05-19 23:46:04 -0700 |
---|---|---|
committer | Father Chrysostomos <sprout@cpan.org> | 2012-05-21 18:09:29 -0700 |
commit | 50853fa94fa95a4fad70b61c9360709826bb8093 (patch) | |
tree | 08332f7abef8085b0f9fdb914f0850a60d92b3ab /lib/overload.t | |
parent | 27b36e73a18363f49fb9cd132ee660376466b5ed (diff) | |
download | perl-50853fa94fa95a4fad70b61c9360709826bb8093.tar.gz |
Make overloaded classes inherit fallback
Before this commit, only classes that had no overloading defined could
inherit the fallback from other classes. If a subclass wanted to
override a single overload setting, it would have to specify the fall-
back value explicitly, to avoid implying fallback=>undef.
We do this by separating the fallback value from overloadedness
itself, so it is possible to have a class that is overloaded, but with
no fallback value.
Previously, the ‘()’ stash entry was used for two purposes. It had a
sub in it so it could be found using usual method lookup mechanims.
The failure to find any such method would be taken for efficiency’s
sake to mean that there was no overloaded, and the search for methods
could end early. The scalar slot contained the fallback entry itself.
To preserve the effiency, we still use &{"()"} to indicate that there
is overloadedness.
Fallback now uses its own entry, named ‘(fallback’. Since it
has to be special-cased anyway, there is no need to add it to
regen/overload.pl.
Diffstat (limited to 'lib/overload.t')
-rw-r--r-- | lib/overload.t | 26 |
1 files changed, 25 insertions, 1 deletions
diff --git a/lib/overload.t b/lib/overload.t index 8ada616bd5..a622cf7fc3 100644 --- a/lib/overload.t +++ b/lib/overload.t @@ -48,7 +48,7 @@ package main; $| = 1; BEGIN { require './test.pl' } -plan tests => 5048; +plan tests => 5050; use Scalar::Util qw(tainted); @@ -2267,6 +2267,30 @@ is "$a", "arakas", 'no overload "fallback" does not stop overload from working'; ok !eval { () = $a eq 'mpizeli'; 1 }, 'no overload "fallback" resets fallback to undef on overloaded class'; +{ package ent; use overload fallback => 0, abs => sub{}; + our@ISA = 'huorn'; + package huorn; + use overload fallback => 1; + package ent; + no overload "fallback"; # disable previous declaration +} +$a = bless [], ent::; +is eval {"$a"}, overload::StrVal($a), + 'no overload undoes fallback declaration completetly' + or diag $@; + +# inherited fallback +{ + package pervyy; + our @ISA = 'vtoryy'; + use overload "abs" =>=> sub {}; + package vtoryy; + use overload fallback => 1, 'sin' =>=> sub{} +} +$a = bless [], pervyy::; +is eval {"$a"}, overload::StrVal($a), + 'fallback is inherited by classes that have their own overloading' + or diag $@; { # undefining the overload stash -- KEEP THIS TEST LAST package ant; |