Overriding object methods (sometimes)

Matt S Trout dbix-class at trout.me.uk
Sat Mar 8 16:29:52 GMT 2008

On Tue, Feb 26, 2008 at 07:59:20PM +0000, Bradley Dean wrote:
> Greetings again,
> On Mon, Feb 25, 2008 at 05:25:33PM +0000, Bradley Dean wrote:
> > I've recently had cause to wrap LWP::UserAgent in a child class
> > which needs to override most public methods. In doing so I've hit up
> > against a problem - these requests call each other, but I only want my
> > child-class methods to be called when I call them.
> Thanks for your thoughts - I'm thinking that the composition path is the
> one to follow. On reflection what I've written is not really valid
> inheritance given that I'd like the class to behave differently when it
> calls on itself. Composition solves this problem exactly and much more
> neatly.

package MyWrapper;

use Moose;
use Method::Signatures;

has '_lwp' => (is => 'ro', isa => 'LWP::UserAgent', handles => '*');

method wrap_lwp_object ($lwp) {
  $self->new(_lwp => $lwp);

before method_i_want_to_wrap => method ($arg) {
  warn "First arg to method_i_want_to_wrap was $arg";


The Method::Signatures is probably overkill, mind :)

      Matt S Trout       Need help with your Catalyst or DBIx::Class project?
   Technical Director                    http://www.shadowcat.co.uk/catalyst/
 Shadowcat Systems Ltd.  Want a managed development or deployment platform?
http://chainsawblues.vox.com/            http://www.shadowcat.co.uk/servers/

More information about the london.pm mailing list