Say your module set is Dpommert::Module, and I'm writing Kyle::Logger. I'd probably set it up this way.
package Kyle::Logger; use Dpommert::Module; Dpommert::Module->set_default_logger( __PACKAGE__ ); package Dpommert::Module; my $default_logger_class = 'Dpommert::Logger'; sub set_default_logger { my $class = shift; die 'class method' if ref $class; $default_logger_class = shift; } sub get_logger { my $self = shift; return $self->{logger} ||= $default_logger_class->new(); } sub set_logger { my $self = shift; $self->{logger} = shift; }
In set_logger and set_default_logger, you may want to use UNIVERSAL::can to make sure what you get has the interface you need.
The way the above works is that a logger class, when it's used, registers itself with the module set. On top of that, any instance of the module can have its logger changed from the default. In this scenario, it's important that Dpommert::Module is used first, contrary to the usage you laid out.
In reply to Re: Polymorphism through use
by kyle
in thread Polymorphism through use
by dpommert
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |