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

run
$run->run;

Actually runs your app

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

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

check_help, cmd_help, cmd_self_completion, cmd_self_pod

Will probably be removed as soon as help is turned into a plugin

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

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, ...)

See App::Spec::Run::Response