>>>>> "TM" == Tom Metro <[EMAIL PROTECTED]> writes:
TM> My understanding is that Perl's OO dereferencing for methods doesn't
TM> involve the object instance, other than to obtain the class name so it
TM> can find the right package namespace. If this is correct, then there
TM> probably isn't a way to do this other than subclassing.
TM> It seems the only option is to do a string eval like:
TM> my $PACKAGE = __PACKAGE__;
TM> eval "package ${PACKAGE}::Module::Under::Test;" . q{
TM> use base qw(Module::Under::Test);
TM> sub method2 { ... }
TM> };
i haven't been following this thread closely but i think i may have a
simple solution for what i understand to be the problem. i could be far
off base but this is an interesting idea below.
why not rebless the instance into its own class, make it inherit its old
class and you can inject new methods into the symbol table of this new
class.
so the idea is that you would take an instance $obj and do something
this (untested rambling code):
my $old_class = ref $obj ;
my $new_class = "$obj" ; # make a unique string from the object ref
bless $obj, $new_class ; # made the object into its own private class
# strict must go since we are accessing through the symbol table
no strict 'refs' ;
unshift @{"${new_class}::ISA"}, $old_class ;
# inject a new method into the new class
my $method = 'bazoom' ;
*{"${new_class}::$method"} = sub { 'do the bazoom' } ;
this is the concept underneath wacko modules like Class::Classless where
each object is its own class.
uri
--
Uri Guttman ------ [EMAIL PROTECTED] -------- http://www.stemsystems.com
--Perl Consulting, Stem Development, Systems Architecture, Design and Coding-
Search or Offer Perl Jobs ---------------------------- http://jobs.perl.org
_______________________________________________
Boston-pm mailing list
[email protected]
http://mail.pm.org/mailman/listinfo/boston-pm