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

Re: thoughts about overloading method calls

Thread Previous | Thread Next
Rafael Garcia-Suarez
May 7, 2008 00:33
Re: thoughts about overloading method calls
Message ID:
2008/5/6 Ricardo SIGNES <>:
>  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

* 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 Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About