develooper Front page | perl.moose | Postings from February 2009

Re: advice on wrapping methods from a superclass

Thread Previous | Thread Next
From:
Dave Rolsky
Date:
February 11, 2009 12:42
Subject:
Re: advice on wrapping methods from a superclass
Message ID:
alpine.DEB.0.9999.0902111441020.18913@urth.org
On Wed, 11 Feb 2009, Oliver Charles wrote:

> On Wed, Feb 11, 2009 at 7:01 PM, Dave Rolsky <autarch@urth.org> wrote:
>> You want to use augment/inner, I think.
>>
>> See
>> http://search.cpan.org/~drolsky/Moose-0.68/lib/Moose/Cookbook/Basics/Recipe6.pod
>> and
>> http://search.cpan.org/~drolsky/Moose-0.68/lib/Moose/Manual/MethodModifiers.pod#INNER_AND_AUGMENT
>
> Actually, I think Jonathan is looking for inner and augment but the
> other way round... Augment works on the subclass, but Jonathan needs
> to run it in the superclass. I ran into just this problem, and ended
> up going with the "sub foo" and "sub _do_foo" approach, but it's not
> the nicest solution.

This is _exactly what augment/inner is for!

  package Parent;

  sub foo {
      my $self = shift;

      $self->wrapper_part1();
      inner();
      $self->wrapper_part2();
  }


  package Child;

  extends 'Parent';

  augment 'foo' => sub {
      my $self = shift;

      $self->fill_in_the_middle();
  };


-dave

/*============================================================
http://VegGuide.org               http://blog.urth.org
Your guide to all that's veg      House Absolute(ly Pointless)
============================================================*/

Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About