I found an alternate solution! I used a dispatch table within each instance, and then created a single accessor method to execute the respective code ref. Took a bit of tweaking, but works like a charm! Thanks for the ideas guys. Both good, and potentially useful for future/different situations.<br clear="all">
<br>Cheers,<br>--<br>Shaun Fryer<br><br><br><div class="gmail_quote">On Sat, May 8, 2010 at 2:25 AM, Uri Guttman <span dir="ltr"><<a href="mailto:uri@stemsystems.com">uri@stemsystems.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">
>>>>> "AH" == Abram Hindle <<a href="mailto:abram.hindle@softwareprocess.es">abram.hindle@softwareprocess.es</a>> writes:<br>
<br>
AH> I have not tried this. I bet you can get MOOSE to do it.<br>
<br>
AH> What I'd try is to generate a new package where the previous class is used as base for that class.<br>
<br>
AH> I'd define those methods within that package and then rebless the instance.<br>
<br>
AH> Make a Gensym sub that can test for existence and then return a random package name;<br>
<br>
AH> you could generate code like this:<br>
AH> package SoAndSo::Prototype::Gensym::XYZABC<br>
<br>
AH> use base qw(SoAndSo);<br>
<br>
AH> *SoAndSo::Prototype::Gensym::XYZABC = $method1;<br>
AH> *SoAndSo::Prototype::Gensym::XYZABC = $method2;<br>
<br>
<br>
AH> bless("SoAndSo::Prototype::Gensym::XYZABC",$instance1);<br>
<br>
just use the reference itself as the package name. it is guaranteed to<br>
be unique. bless the object into its own class, set the @ISA to look at<br>
the parent class. this is basically what stuff like class::classless<br>
does. every object is its own class and has its own @ISA, namespace and<br>
methods. you can still inherit as you wish by controlling @ISA.<br>
<br>
something like:<br>
<br>
my $package = "$obj" ;<br>
bless $obj, $package ;<br>
@{"${package}::ISA"} = $parent_class ; # no strict refs for this<br>
<br>
*{"${package}::$method"} = sub { print "i am a method of $package" } ;<br>
<br>
much simpler than all the code so far.<br>
<br>
uri<br>
<font color="#888888"><br>
--<br>
Uri Guttman ------ <a href="mailto:uri@stemsystems.com">uri@stemsystems.com</a> -------- <a href="http://www.sysarch.com" target="_blank">http://www.sysarch.com</a> --<br>
----- Perl Code Review , Architecture, Development, Training, Support ------<br>
--------- Gourmet Hot Cocoa Mix ---- <a href="http://bestfriendscocoa.com" target="_blank">http://bestfriendscocoa.com</a> ---------<br>
</font></blockquote></div><br>