in reply to replace object methods at runtime
Well, you can hide it using AUTOLOAD
and then declare the default methods for your objects as:# 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"; }
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 |