diff options
author | Father Chrysostomos <sprout@cpan.org> | 2012-05-20 14:55:08 -0700 |
---|---|---|
committer | Father Chrysostomos <sprout@cpan.org> | 2012-05-21 18:09:35 -0700 |
commit | 1d6df9f86ed4c2dd82004200f6de623daf22bf5e (patch) | |
tree | e4ac9c3824f738042bbd0dce0f0f83acb99c39af /lib/overload.t | |
parent | 88650ec45d61ee3b9104c6b15b145719a65af2ea (diff) | |
download | perl-1d6df9f86ed4c2dd82004200f6de623daf22bf5e.tar.gz |
overload.pm: Allow :: in method names
According to overload’s documentation, ‘[v]alues specified as strings
are interpreted as method names.’
But it behaves differently if the string contains a double colon:
use overload q\""\=>"bar::baz";
@bar::ISA = foo;
sub foo::baz{a}
warn bless[]
__END__
Undefined subroutine &bar::baz called at - line 4.
But apostrophes work as documented:
use overload q\""\=>"bar'baz";
@bar::ISA = foo;
sub foo::baz{a}
warn bless[]
__END__
a at - line 4.
I can’t see how the treatment of ::, introduced in a60067777, is not a
bug, though the method logic looks intentional:
+ if (not ref $sub and $sub !~ /::/) {
I suspect it was one of those things that was just not thought
through. The pre-a60067777 logic was in gv.c, and treated strings
containing package separators just like any other strings:
switch (SvTYPE(sv)) {
default:
if (!SvROK(sv)) {
if (!SvOK(sv)) break;
gv = gv_fetchmethod(stash, SvPV(sv, na));
if (gv) cv = GvCV(gv);
break;
}
cv = (CV*)SvRV(sv);
Diffstat (limited to 'lib/overload.t')
-rw-r--r-- | lib/overload.t | 16 |
1 files changed, 15 insertions, 1 deletions
diff --git a/lib/overload.t b/lib/overload.t index fed261dafb..7657010a2a 100644 --- a/lib/overload.t +++ b/lib/overload.t @@ -48,7 +48,7 @@ package main; $| = 1; BEGIN { require './test.pl' } -plan tests => 5051; +plan tests => 5053; use Scalar::Util qw(tainted); @@ -2297,6 +2297,20 @@ is eval {"$a"}, overload::StrVal($a), 'fallback is inherited by classes that have their own overloading' or diag $@; +# package separators in method names +{ + package mane; + use overload q\""\ => "bear::strength"; + use overload bool => "bear'bouillon"; +} +@bear::ISA = 'food'; +sub food::strength { 'twine' } +sub food::bouillon { 0 } +$a = bless[], mane::; +is eval { "$a" }, 'twine', ':: in method name' or diag $@; +is eval { !$a }, 1, "' in method name" or diag $@; + + { # undefining the overload stash -- KEEP THIS TEST LAST package ant; use overload '+' => 'onion'; |