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


in reply to Showing global options while using App::Cmd

Personally I avoid global_opt_spec and instead use a base class for all commands. Let's say my app is called MyApp, then I'll do it like this:

{ package MyApp::Command; # abstract use strict; use App::Cmd::Setup-command; sub opt_spec { return ( [ 'someopt' => 'This is a global option' ], ); } # you can also define any helper methods you like here # and all your commands will have easy access to them. } { package MyApp::Command::foo; use strict; use MyApp-command; sub opt_spec { my $self = shift; return ( $self->SUPER::opt_spec(@_), [ 'otheropt' => 'This is another option' ], ); } }
perl -E'sub Monkey::do{say$_,for@_,do{($monkey=[caller(0)]->[3])=~s{::}{ }and$monkey}}"Monkey say"->Monkey::do'