More easily explained with an example:
my $o = SpecialEffects->new( "config" => 'a' );
my $p = SpecialEffects->new( "config" => 'b' );
$o->sound(); # aliased to fizz(); same as $o->fizz()
$p->sound(); # aliased to clonk(); same as $p->clonk()
Is it possible to do this in Perl? Perhaps using some typeglob or coderef trickery?
I'm trying to keep the SpecialEffects
interface simple. I'd prefer not to start building an object hierarchy. The sound()
method is what's exposed, only its behaviour can be configured slightly.
I already know that you can alias with *sound = \&fizz;
but that is a global thing as far as I know, and I'd like it encapsulated in the object.