in reply to Dynamically setting up inheritence at runtime

This doesn't work because @ISA is a class variable, not an instance variable. You're trying to change the behavior of instances within one class, so you'd have to do that with differences in the instances. On initialization, you can take note of what the "base" class is to be and then use that within the instance.

package foo; sub new{ my $class = shift; my $base = shift; return bless { base_class => $base }, $class; } sub write{ my $self = shift; my $base = $self->{base_class}; print eval "\$self->$base\::read"; }

I used eval because my other attempts at getting this to work didn't.

no strict 'refs'; print $self->&{"$base\::read"}; # syntax error # string found where operator expected print $self->"$base\::read"; # executes but ignores $base's inheritance, if any no strict 'refs'; print &{"$base\::read"}( $self );

This is not to say I recommend using eval for this. In fact, I think it's another argument that what you're trying to do isn't a very good idea.

I'd encourage you to consider object composition instead of some funny inheritance.

If you're dead set on this, you'll probably have to resort to something like what I did in Overloading different instances differently.. Every instance will be in its own package set up with its own @ISA that refers to both "Foo" and either "Alpha" or "Beta". Or something like that.

This kind of works too:

# code above package foo unchanged package foo::alpha; BEGIN { @foo::alpha::ISA = qw( foo alpha ); } package foo::beta; BEGIN { @foo::beta::ISA = qw( foo beta ); } package foo; sub new{ my $class = shift; my $base = shift; return bless {}, "$class\::$base"; } # all other code unchanged

I can't say I recommend that either, but it's better than eval.