in reply to Redefining methods in non-singletons nearly drove me mad today

If you really want to redefine methods on a per-object basis, one way to do it is to construct a new class for each object which inherrits from your base class. For example:

package shortTest; use strict; 1; sub new { my $class = shift; my ( $name ) = @_; my $self = {}; my $new_class = $class . '::' . $self; { no strict 'refs'; @{ $new_class . '::' . 'ISA' } = ( $class ); *{ $new_class . '::' . 'getName' } = \&showName; } bless $self, $new_class; $self->{name} = $name; return $self; } sub updateName { my $self = shift; my $class = ref $self; no strict 'refs'; *{ $class . '::' . 'getName' } = \&showName2; }
Update: Added no strict 'refs'