On Fri, Oct 05, 2007 at 11:05:50AM -0700, Allison Randal wrote:
> Patrick R. Michaud wrote:
> >
> >At any rate, pgc.pir and Perl6Grammar.pir (used to compile
> >grammars into PIR) both want the ability to compile and install rules
> >at runtime, so we really need the eval version to work before
> >we can progress much.  Either that or I'll come up with a workaround
> >for those.
> 
> The preferred way of adding methods at runtime is to call 'add_method' 
> on the class object.

Sure.  It just seems that compiling PIR code (at runtime) where the 
subs are tagged with :method ought to do the same, without the need for
a separate 'add_method' step.  

In the case of dynamically generated code, using add_method is 
somewhat more challenging because we can't perform the add_method 
until after the PIR source has been compiled and loaded into the
namespace.  That means that in addition to runtime-compiling
the source, we have to keep around a list of any methods contained
within that source so that we can then look them up and do individual
add_method calls for each.  Either that or the source itself has to
have a :load/:init routine to do the add_method calls.

Either way, tagging subs with :method is far cleaner.  Anything else
feels like a serious kludge.  :-)

Pm

Reply via email to