Try as I might, I can't get two instances of a class to have different inheritance trees at the same time. @ISA is a package variable, so changing it affects all instances. Hmm, can @ISA be tied? You'd have to invalidate the cache every time you did anything and this would be bad, wicked, evil, wrong, etc., but I'm still curious to know if it can be done.
Or ... maybe I could bless every instance into an anonymous subclass and ... oh wait, I can't tie symbol tables. Damn. Maybe I could use anonymous subclasses, do some introspection and pulled out method names and provided wrapper which switched @INC that way...
ACME::DiddleMyInc needs to be written!
The closest I've come up with so far is this:
#!/usr/bin/perl -l
use strict;
use warnings;
{
package KillMeNow;
sub whee { return 'whee!' }
sub new { bless {}, shift }
}
{
package DontKillMe;
sub whee { return 'asdfasdf' }
}
{
package KillMeLater;
@KillMeLater::ISA = 'KillMeNow';
use overload '%{}' => sub {
@KillMeLater::ISA =
rand 1 >.5
? 'KillMeNow'
: 'DontKillMe';
return shift;
},
fallback => 1;
sub new { bless {} => shift }
sub whee {
my $self = shift;
no warnings 'void';
%$self;
$self->SUPER::whee;
}
}
for ( 1.. 20 ) {
print KillMeLater->new->whee;
}
It works, but it's not what I wanted. I could possibly automate that, but this is harder than it seems.
Re:Full power...now sir.
Ovid on 2007-04-19T15:11:02
Yeah, we were talking about that here at work. It would have solved an annoying little problem here (well, more of a hack to get around some buggy CPAN code).
Re:why?
Ovid on 2007-04-19T15:37:20
Note the Acme:: prefix on the suggested namespace.
Re:use Moose
Aristotle on 2007-04-20T00:18:04
That would be my angle of attack also.
Re:What EXACTLY are you trying to do...
Ovid on 2007-04-20T08:00:45
It's not that I want to have different instances with different inheritance trees. I just want to know if it can be done. It's a matter of curiosity, that's all.