overload.pm: Allow :: in method names
authorFather Chrysostomos <sprout@cpan.org>
Sun, 20 May 2012 21:55:08 +0000 (14:55 -0700)
committerFather Chrysostomos <sprout@cpan.org>
Tue, 22 May 2012 01:09:35 +0000 (18:09 -0700)
commit1d6df9f86ed4c2dd82004200f6de623daf22bf5e
treee4ac9c3824f738042bbd0dce0f0f83acb99c39af
parent88650ec45d61ee3b9104c6b15b145719a65af2ea
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);
lib/overload.pm
lib/overload.t