"be consistent" | |
PerlMonks |
Re: Can anybody tell me how MooX::Cmd is supposed to work?by tobyink (Canon) |
on Mar 14, 2013 at 09:23 UTC ( [id://1023430]=note: print w/replies, xml ) | Need Help?? |
The documentation is pretty sparse, isn't it? Here's an example:
If you save that as calc.pl you can run it like this:
MooX::Cmd doesn't really "do" much. It's really just some glue allowing you to create commands that have subcommands. If you don't know what I mean by subcommands, git is an example. (Pretty much all command-line tools for version control systems are.) You don't type:
Instead you need to provide a subcommand:
If you don't need subcommands, then don't use MooX::Cmd; just use MooX::Options (which does the @ARGV handling). And frankly, if you do need subcommands, I'd rather go with App::Cmd which is IMHO a better, more integrated approach to writing command line apps. My general technique for command-line apps in fact is to use Moo or Moose classes and roles for the "business logic", and then use App::Cmd for the command-line glue. On-demand run-time loading of the classes and roles can result in a pretty snappy command-line interface, even if using the slow old Moose!
package Cow { use Moo; has name => (is => 'lazy', default => sub { 'Mooington' }) } say Cow->new->name
In Section
Seekers of Perl Wisdom
|
|