NAME
App::Spec::Run - App::Spec framework to run your app
DESCRIPTION
App::Spec::Run is the framework which runs your app defined by the spec. Your app class should inherit from App::Spec::Run::Cmd.
SYNOPSIS
sub your_command {
my ($self, $run) = @_;
my $options = $run->options;
$run->out("It works");
}
METHODS
- Constructor
-
You can create the object yourself like this:
my $run = App::Spec::Run->new( spec => $appspec, cmd => App::YourApp->new, );
Or you use the runner method of App::Spec, which will create it for you:
my $run = $appspec->runner(...);
Both methods take optional arguments:
my $run = App::Spec::Run->new( spec => $appspec, cmd => App::YourApp->new, # Custom array instead of the default ARGV. # The contents of this array will be modified argv => \@my_arguments, );
- run
-
$run->run;
Actually runs your app. Calls
process
andfinish
. - process
-
$run->process;
Processes input, validates, runs your command and fills the response object.
Does not print the output and does not exit.
- out
-
$run->out("Hello world!");
Appends to response output. Adds a newline if not present. You can also pass a data structure:
$run->out($hashref);
This will be formatted with Data::Dumper.
See also App::Spec::Plugin::Format.
- err
-
$run->err("Oops, that went wrong");
Appends to response error output. Adds a newline if not present
- halt
-
$run->halt;
Further processing is halted.
- finish
-
$run->finish;
Prints the output and exits with the exit code stored in
response
. - process_input
-
$run->process_input( option_specs => \%option_specs, param_specs => \%param_specs, );
- process_parameters
-
$run->process_parameters( parameter_list => $global_parameters, param_specs => $param_specs, );
- run_op
-
$run->run_op("yourcommand"); # shortcut for $run->cmd->yourcommand($run);
- completion_output
-
$run->completion_output( param_specs => \%param_specs, completion_parameter => $completion_parameter, );
Is called when in completion mode
- colored
-
Returns the given text colored, if colors are active for the given output.
$msg = $run->colored('err', [qw/ error /], "Oops"); $msg = $run->colored('out', [qw/ green /], "Everything is fine!");
- colorize
-
my $color_active = $run->colorize('out'); my $color_error_active = $run->colorize('err');
Returns 1 or 0 if given output color are active. That means, the output is going to a terminal instead of being redirected.
- colorize_code
-
my $colored = $run->colorize_code('out'); my $text = $colored->(['green'], "Hurray"); # or my $text = "Hurray"; $colored->(['green'], $text);
Returns a coderef which you can use for coloring
- colorize_error
-
my $msg = $run->colorize_error("ouch");
Returns the message in the standard error color (bold red).
- error_output
-
$run->error_output;
Outputs any errors.
Calls
halt
- event_globaloptions
-
Calls any plugin that needs to know
- subscribe
-
A plugin can subscribe for an event:
$run->subscribe( print_output => { plugin => $self, method => "print_output", },
ATTRIBUTES
- spec
-
Your spec, (App::Spec)
- options
-
A hashref with the given options
{ verbose => 1, foo => 23, }
- parameters
-
A hashref with the given parameters
- commands
-
An arrayref containing all subcommands from the commandline
- argv_orig
-
This contains the original contents of
argv
before processing - argv
-
This is a reference to the commandline arguments array
@ARGV
, or the array reference you specified otherwise. When calling your command method, it will contain the rest of the arguments which weren't processed as any subcommand, option or parameter. - validation_errors
-
Contains errors from option/parameter validation
- op
-
Contains the operation (subroutine) which will be executed to run yor command
- cmd
-
This is an instance of your app class
- response
-
This contains the response of your command (exit code, output, ...)
- subscribers
-
Contains a hashref
{ print_output => { module => $plugin, method => 'print_output', }, }