plugins, hooks and subclassing

Robbie Bow robbie at robbiebow.co.uk
Thu Oct 11 22:49:43 PDT 2007


package Toms::Message;
use strict;

sub text {

print qq~
-------- Original Message  --------
Subject: Re:plugins, hooks and subclassing
From: Tom Hukins <tom at eborcom.com>
To: Milton Keynes Perl Mongers <miltonkeynes-pm at pm.org>
Date: 11 October 2007 17:45:48

> On Fri, Oct 05, 2007 at 04:54:28PM +0100, Oliver Gorwits wrote:
>> For a module which is OO with no functional interface, as the author
>> I'd prefer not to have to touch lots of the code to add hooks. This
>> is something OO naturally serves well, to my mind.
> 
> Yes, that sounds sensible to me.  I held off replying in case someone
> had more helpful ideas, but as nobody's replied yet I thought I might
> as well.
> 
>> What opinions on plugins/hooks/subclassing are out there?
> 
> Plenty, I'm sure. :)
> 
> Personally, I'd suggest your user tries to subclass your module:
>   sub method {
>       my $self = shift;
>       # Do things here, if necessary
>       $self->SUPER::method(@_);
>       # Do things here, if necessary
>   }
> 
> If Perl's inheritance order causes problems, take a look at Class:C3.
> If you feel you need a heavyweight plugin system, use
> Module::Pluggable.  I've used both, and like both, but wouldn't use
> them unless I had a problem with what Perl already provides.
> 
> Tom
> _______________________________________________
> MiltonKeynes-pm mailing list
> MiltonKeynes-pm at pm.org
> http://mail.pm.org/mailman/listinfo/miltonkeynes-pm
> 
~~;


package main;
use strict;
use base qw(Toms::Message);

...

sub message {
   my $self = shift;
   print "I agree";
   $self->SUPER::message();
}


More information about the MiltonKeynes-pm mailing list