App::Spec::Run(3)
β¨ App::Spec::Run β¨
okay so bestie, welcome to the App::Spec::Run manpage β that's the perl doc for the App::Spec::Run module, and it's literally the whole framework that runs your app π
π NAME π
App::Spec::Run β the App::Spec framework that runs your app. yes, that's the whole name, we're keeping it, periodt π
πΈ DESCRIPTION πΈ
So App::Spec::Run is the framework that actually runs your app β the app you defined with your spec β¨
Here's the tea though: your app class should inherit from App::Spec::Run::Cmd. That's the vibe check you gotta pass, no cap π«Ά
π§ SYNOPSIS π§
sub your_command {
my ($self, $run) = @_;
my $options = $run->options;
$run->out("It works");
}
like, that's it. that's the whole energy π₯
π METHODS π
π Constructor
You can build the object yourself, main character style:
my $run = App::Spec::Run->new(
spec => $appspec,
cmd => App::YourApp->new,
);
Or you can just use the runner method of App::Spec and let it do the work for you, icon behaviour honestly:
my $run = $appspec->runner(...);
Both methods take optional arguments, so you can customize:
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,
);
heads up bestie: the contents of that array will be modified β that's not a drill π
π run
$run->run;
This is the one that actually runs your app. It calls "process" and then "finish". slay π
πΈ process
$run->process;
Processes the input, validates it, runs your command, and fills up the response object. lowkey the whole pipeline β¨
Important though: it does not print the output, and it does not exit. It just does the work and minds its business π§
π out
$run->out("Hello world!");
Appends stuff to the response output. It adds a newline if there isn't one already β thoughtful queen behaviour π
You can also hand it a data structure:
$run->out($hashref);
and that gets formatted with Data::Dumper β¨
See also App::Spec::Plugin::Format.
π err
$run->err("Oops, that went wrong");
Appends to the response error output. Adds a newline if not present π
π¦ halt
$run->halt;
Further processing is halted. that's it, we're done here, bye π
β finish
$run->finish;
Prints the output and exits with the exit code stored in "response". so it's the grand finale basically π
πΈ 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);
it's giving "convenience wrapper", we love a shortcut β¨
π§ completion_output
$run->completion_output(
param_specs => \%param_specs,
completion_parameter => $completion_parameter,
);
Is called when you're in completion mode π¦
π colored
Returns the given text colored β but only if colors are actually 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 depending on whether the given output's color is active. And what does that mean? it 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 you can use for coloring. very "here's a little tool, go off" of it π
πΈ colorize_error
my $msg = $run->colorize_error("ouch");
Returns the message in the standard error color, which is bold red π₯π
π¦ error_output
$run->error_output;
Outputs any errors. And it calls "halt" β dramatic but valid π
π event_globaloptions
Calls any plugin that needs to know π
π subscribe
A plugin can subscribe to an event, like this:
$run->subscribe(
print_output => {
plugin => $self,
method => "print_output",
},
group chat for plugins, honestly π«Ά
π ATTRIBUTES π
π spec
Your spec β that's an App::Spec β¨
πΈ options
A hashref with the given options, like:
{
verbose => 1,
foo => 23,
}
π¦ parameters
A hashref with the given parameters π
β commands
An arrayref containing all the subcommands from the commandline π
π₯ argv_orig
Contains the original contents of "argv" before processing. the before pic πΈ
π argv
This is a reference to the commandline arguments array @ARGV, or to the array reference you specified otherwise π«Ά
When your command method gets called, it will contain the rest of the arguments β the ones that weren't processed as any subcommand, option or parameter β¨
π validation_errors
Contains errors from option/parameter validation π
π§ op
Contains the operation (subroutine) that will be executed to run your 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.
π subscribers
Contains a hashref, like:
{
print_output => {
module => $plugin,
method => 'print_output',
},
}
that's the whole page bestie, you're so welcome π«Άβ¨ peri v5.42.0, dated 2025-03-26 β mwah, catch you in the next manpage ππ
π¦ where this page comes from
- opensuse-leap 16.0: perl-App-Spec 0.15.0-bp160.1.1 Β· Artistic-1.0 OR GPL-1.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms