So, I'm reading various things about lots of changes for perl6, and some
arcane things going away, and stuff like that.. and I suddenly wondered
if one of my favorite features of Perl Objects (the one that keeps me
from migrating to tcl or python, cuz I can never find clear information
about whether such an analog exists in those languages) is going away:
AUTOLOAD.

I thought I'd ask here ... I'm sorry if this type of question wasn't
intended to be discussed on this particular list (like, if it's only for
hard-core internals developers, as opposed to a place for outsiders to
ask questions about what's going on in the future of Perl).

Let me explain why it's important to me:

At heart, whenever I program with objects, I am a smalltalk programmer. 
So, when I saw perl aquire objects in the transition from perl4 to
perl5, I wondered how hard it would be to make a stronger delination
between class methods and instance methods in perl5.

At first I used AUTOLOAD to make an ulgy hack of a way of doing it
(class methods start with _ and instance methods start with __ ... but
you'd invoke them without the leading _ or __ ... and Autoload would
figure out which one you meant based on whether or not the caller was a
reference).  I tacked on an Openstep-ism (delegates: class A, if it is a
subclass of class B, can declare that it will intercept calls to class
B.  Thus, when you ask to instantiate class B, you will actually get an
instance of class A ... which has usually overloaded some of class B's
methods for slightly different behavior; this means that existing
software doesn't have to be rewritten to use (nor even know about the
existance of class A) in order to get its new features).  All of this
was implimented in the base Object class.

But the delcaration mechanism always bugged me.  I recently started
doing more work on one of my projects that uses this mechanism, and
decided that along the way I was going to re-do the above thingy.  So
now, I have a package named "PerlTalk" which has a variable $Library. 
$Library looks like this:

$Perltalk::Library{$classname}{Imethod}{$methodname} = sub {};
$Perltalk::Library{$classname}{Cmethod}{$methodname} = sub {};
$Perltalk::Library{$classname}{Cvars}{$variablename} = # some value
$Perltalk::Library{$classname}{Delegate} = "SomeOtherClassName";


The first two lines are how you declare instance methods (Imethod) and
class methods (Cmethod).  The third one provides a place to put class
variables in a uniform kinda place, and the fourth item where you'd set
the notion of a class' delegate (in the above example, it'd be like:
$Perltalk::Library{ClassB}{Delegate} = "ClassA"; ).  I'm also
considering allowing method delcarations to be strings, and adding into
my AUTOEXEC the ability to recognize that and alter its behavior
accordingly.  So, you could have CODE methods and eval'ed SCALAR string
methods.


Then when you send a message, AUTOEXEC figures out whether it needs to
call the class method or instance method, and stuff.  The one drawback
is that I have to actually figure out how to do the inheritance
mechanics since these methods aren't declared in a way that the normal
mechanism recognizes.  The old mechanism did work with the normal perl
inheritance.  

(I'm currently choosing between two approaches: 1) have AUTOLOAD
recursively search through the class's inheritance chain to find the
method (slow at runtime), or 2) instead of declaring inheritance via
"@ISA = ", you'd call a subroutine, such as "inherit(MyClass,
MySuperClass);" which sets up your @ISA inheritance fo you, AND copies
your superclass's method delcarations into your current space, so then
AUTOLOAD wont have to do a very detailed search through $Library to find
your method (slow at compile/run time).)


ANYWAYS ... that's a long way around to asking:

Will Perl6 still have "AUTOLOAD"?  And will it still work in a way that
is compatible with what I'm doing here?


(I'm also curious if anyone else out there finds any of that
interesting.)

-- 
John "kzin" Rudd                       http://people.ucsc.edu/~jrudd
Truth decays into beauty, while beauty soon becomes merely charm. Charm
ends up as strangeness, and even that doesn't last. (Physics of Quarks)
   -----===== Kein Mitleid Fu:r MicroSoft (www.kmfms.com) ======-----

Reply via email to