I sent this on Tue, but it never came back to me from the list, so here
it is again.  Sorry if anyone gets a repeat.

Begin forwarded message:

Date: Tue, 10 Aug 2004 13:58:47 -0700
From: Michel Pelletier <[EMAIL PROTECTED]>
To: [EMAIL PROTECTED]
Cc: [EMAIL PROTECTED]
Subject: Re: [perl #31031] Need a way to access the namespace of a class object


> From: Dan Sugalski (via RT) <[EMAIL PROTECTED]>
> To: [EMAIL PROTECTED]
> Reply-To: [EMAIL PROTECTED]
> Subject: [perl #31031] Need a way to access the namespace of a class object 
> Date: Mon, 09 Aug 2004 14:09:04 -0700
> 
> # New Ticket Created by  Dan Sugalski 
> # Please include the string:  [perl #31031]
> # in the subject line of all future correspondence about this issue. 
> # <URL: http://rt.perl.org:80/rt3/Ticket/Display.html?id=31031 >
> 
> 
> We need a way to get a handle on a class object's namespace or, 
> alternately, a scheme to allow adding a method by name to a class 
> object.

Can't the second thing be done now?  Maybe I don't understand or I'm
doing it wrong in Parakeet, but I create classes initially and later on
add methods to them by compiling PIR:

(in Parakeet)

0> class foo meth bar "hi!" println end end
0> see foo
.namespace["foo"]
.sub _bar method
inc .LEVEL
new_pad .LEVEL
.TOS = new .PerlString
.TOS = "hi!"
.PUSH
.POP
print .TOS
print "\n"
pop_pad
.pcc_begin_return
.pcc_end_return
.end
0> 

The class object is created by the word 'class'.  'meth' starts a new
method body which PIR gets emitted to during compilation, and then 'end'
(the first end that ends the meth definition) compiles it with the
"compile" opcode.  Notice that the PIR doesn't contain the class
definition, only the methods.  The class already exists when this code
is compiled.

It works for me, I can add any number of methods to a class by name.

-Michel

Reply via email to