App::Spec - Specification for commandline apps
WARNING: This is still experimental. The spec is subject to change.
This module represents a specification of a command line tool. Currently it can read the spec from a YAML file or directly from a data structure in perl.
It uses the role App::Spec::Role::Command.
The App::Spec::Run module is the framework which will run the actual app.
Have a look at the App::Spec::Tutorial for how to write an app.
In the examples directory you will find the app myapp which is supposed to demonstrate everything that App::Spec supports right now.
myapp
Your script:
use App::Spec; my $spec = App::Spec->read("/path/to/myapp-spec.yaml"); my $run = $spec->runner; $run->run; # this is equivalent to #my $run = App::Spec::Run->new( # spec => $spec, # cmd => Your::App->new, #); #$run->run;
Your App class:
package Your::App; use base 'App::Spec::Run::Cmd'; sub command1 { my ($self, $run) = @_; my $options = $run->options; my $param = $run->parameters; # Do something $run->out("Hello world!"); $run->err("oops"); # you can also use print directly }
my $spec = App::Spec->read("/path/to/myapp-spec.yaml");
Takes a file, hashref or glob and returns generated appspec hashref
my $hash = $class->load_data($file);
Builds objects out of the hashref
my $appspec = App::Spec->build(%hash);
Returns an instance of the your app class
my $run = $spec->runner; $run->run; # this is equivalent to my $run = App::Spec::Example::MyApp->new({ spec => $spec, }); $run->run;
Returns usage output for the specified subcommands:
my $usage = $spec->usage( commands => ["subcommand1","subcommand2"], );
Generates shell completion script for the spec.
my $completion = $spec->generate_completion( shell => "zsh", );
Returns options for Getopt::Long
my @getopt = $spec->make_getopt($global_options, \%options, $option_specs);
Accessors for the things defined in the spec (file)
App::AppSpec - Utilities for App::Spec authors
This library is free software and may be distributed under the same terms as perl itself.
To install App::Spec, copy and paste the appropriate command in to your terminal.
cpanm
cpanm App::Spec
CPAN shell
perl -MCPAN -e shell install App::Spec
For more information on module installation, please visit the detailed CPAN module installation guide.