inheritance - In Perl/Moose, how can I apply a modifier to a method in all subclasses? -
i have moose class intended subclassed, , every subclass has implement "execute" method. however, put apply method modifier execute method in class, applies execute method in subclasses. method modifiers not preserved when method overriden. there way ensure subclasses of class have method modifier applied execute methods?
example: in superclass, have this:
before execute => sub { print "before modifier executing.\n" }
then, in subclass of that:
sub execute { print "execute method running.\n" }
when execute method called, doesn't "before" modifier.
this augment
method modifier made for. can put in superclass:
sub execute { print "this runs before subclass code"; inner(); print "this runs after subclass code"; }
and instead of allowing subclasses override execute
directly, have them augment
it:
augment 'execute' => sub { print "this subclass method"; };
basically gives functionality that's around
modifier, except parent/child relationship changed.
Comments
Post a Comment