Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

Re: Showing global options while using App::Cmd

by tobyink (Abbot)
on Sep 25, 2012 at 08:29 UTC ( #995509=note: print w/ replies, xml ) Need Help??


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'


Comment on Re: Showing global options while using App::Cmd
Select or Download Code
Re^2: Showing global options while using App::Cmd
by McA (Deacon) on Sep 25, 2012 at 08:52 UTC

    Hi tobyink,

    thank you for the fast reply.

    Am I right, that all these "base" options would show up as command options?

    Do you know a way to solve my initial problem if I really want the distinction between global and command specific options?

    Best regards
    McA

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://995509]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others taking refuge in the Monastery: (11)
As of 2014-07-11 14:01 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    When choosing user names for websites, I prefer to use:








    Results (227 votes), past polls