diff options
author | Father Chrysostomos <sprout@cpan.org> | 2012-05-23 01:05:20 -0700 |
---|---|---|
committer | Father Chrysostomos <sprout@cpan.org> | 2012-05-23 06:01:23 -0700 |
commit | 3866ea3be51f0998b848d22c4ef960965bda7199 (patch) | |
tree | 0bdd788345c8cb865f6aa7c4358c6896c38867ea /lib/overload.pm | |
parent | 1204c818c5b6fdbe987017df9f2ce0e68463f315 (diff) | |
download | perl-3866ea3be51f0998b848d22c4ef960965bda7199.tar.gz |
[perl #113050] Put fallback back under "()"
Unfortunately, there is code all over CPAN that assumes fallback is
stored under the "()" stash entry. And that code also assumes that
the overloadedness flag (the existence of the CV) is in the same spot.
So much for encapsulation.
This commit changes overloading itself to use a different key, "((",
while having it search for "()" first, and then "((" only if "()" is
not found, to preserve compatibility with encapsulation-breaking code.
So the "((" key will only be used by gv.c if there is no fallback
value specified at all.
Diffstat (limited to 'lib/overload.pm')
-rw-r--r-- | lib/overload.pm | 9 |
1 files changed, 5 insertions, 4 deletions
diff --git a/lib/overload.pm b/lib/overload.pm index ed69440438..c1eefc018d 100644 --- a/lib/overload.pm +++ b/lib/overload.pm @@ -31,10 +31,10 @@ sub OVERLOAD { $package = shift; my %arg = @_; my ($sub, $fb); - *{$package . "::()"} = \&nil; # Make it findable via fetchmethod. + *{$package . "::(("} = \&nil; # Make it findable via fetchmethod. for (keys %arg) { if ($_ eq 'fallback') { - for my $sym (*{$package . "::(fallback"}) { + for my $sym (*{$package . "::()"}) { *$sym = \&nil; # Make it findable via fetchmethod. $$sym = $arg{$_}; } @@ -62,17 +62,18 @@ sub import { sub unimport { $package = (caller())[0]; shift; + *{$package . "::(("} = \&nil; for (@_) { warnings::warnif("overload arg '$_' is invalid") unless $ops_seen{$_}; - delete $ {$package . "::"}{"(" . $_}; + delete $ {$package . "::"}{$_ eq 'fallback' ? '()' : "(" .$_}; } } sub Overloaded { my $package = shift; $package = ref $package if ref $package; - mycan ($package, '()'); + mycan ($package, '()') || mycan ($package, '(('); } sub ov_method { |