in reply to replace object methods at runtime

But if I could skip this level of indirection I will be happy.

Well, you can hide it using AUTOLOAD

# untested sub AUTOLOAD { if (my ($pkg, $name) = $AUTOLOAD =~ /^((?:.*::)?)(.*)$/) { $name =~ /^_default_(.*)/ and croak "method $1 not found"; my $sub = sub { my $method = $_[0]->{m}{$name}; goto &$method if defined $method; my $default = "_default_$name" shift->$default(@_); } no strict 'refs'; *$AUTOLOAD = $sub; goto &$sub; } croak "bad method name $AUTOLOAD"; }
and then declare the default methods for your objects as:
sub _default_foo { ... } sub _default_bar { ... } ...

Replies are listed 'Best First'.
Re^2: replace object methods at runtime
by karavelov (Monk) on Jun 24, 2008 at 15:40 UTC
    Thank you for all the suggestions and especially to salva - I have taken the AUTOLOAD road (there is a rhyme here :)

    Thanks also to Narveson. Basically the AUTOLOAD makes you the wrapper functions when they are needed. It is really good because I don't want to hand write them by hand.

    I know that one day I have to go for Moose. May be sooner than I expected.

    Thanks again