develooper Front page | perl.perl5.porters | Postings from May 2008

Re: thoughts about overloading method calls

Thread Previous | Thread Next
From:
Rafael Garcia-Suarez
Date:
May 7, 2008 00:33
Subject:
Re: thoughts about overloading method calls
Message ID:
b77c1dce0805070033w7269c2bds220f229bb5c8fe48@mail.gmail.com
2008/5/6 Ricardo SIGNES <perl.p5p@rjbs.manxome.org>:
>  What if, instead, I could overload method calls on an object?
>
>   package Classless::Root;
>   use overload method => 'invoke_method';

use overload '->' => \&invoke; # more graphic ?

Let's try to think a bit more about this :

* that would work only for instance methods, not class methods

* that would step over AUTOLOADed methods -- AUTOLOAD would never
  be called in presence of -> overloading

* would that step over regular, existing, defined methods ?
  If it doesn't, we can instruct invoke() to install new methods,
  à la AUTOLOAD.

* We will need to avoid calling methods on the same object from inside
  invoke(), to avoid deep recursion.

* What if someones invokes the "(->" method directly ? (the
  internal name of "invoke()".) Maybe all overload methods
  (whose names begin with "(") should be excluded from this
  mechanism.

* We will probably want a nice way to throw the error "Can't locate
  object method %s via package %s", like a new builtin, or a core
  function in the overload package

* Of course, subclasses will inherit that overloading.

I'm not familiar with the implementation of overloading in the core.
That doesn't sound like something really difficult to implement, but
don't take my word for it.

Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About