http://www.perlmonks.org?node_id=1008110


in reply to Right place to put common execute code in App::Cmd

This is the kind of place where aspect-oriented programming is awesome. If you're using Moose, Moo or another OO library that supports method modifiers, then it's probably just a matter of creating a role with a before execute method modifier and then applying it to all your command classes.

Otherwise, if you have a base class for all your command classes, you could try creating a method called before_execute and then manually modifying all your execute methods to call $_[0]->before_execute at the start.

perl -E'sub Monkey::do{say$_,for@_,do{($monkey=[caller(0)]->[3])=~s{::}{ }and$monkey}}"Monkey say"->Monkey::do'