App-Cmd
view release on metacpan or search on metacpan
lib/App/Cmd/Command.pm view on Meta::CPAN
sub opt_spec {
return;
}
#pod =method validate_args
#pod
#pod $command_plugin->validate_args(\%opt, \@args);
#pod
#pod This method is passed a hashref of command line options (as processed by
#pod Getopt::Long::Descriptive) and an arrayref of leftover arguments. It may throw
#pod an exception (preferably by calling C<usage_error>, below) if they are invalid,
#pod or it may do nothing to allow processing to continue.
#pod
#pod =cut
sub validate_args { }
#pod =method usage_error
#pod
#pod $self->usage_error("This command must not be run by root!");
lib/App/Cmd/Command.pm view on Meta::CPAN
list of arguments passed to C<describe_options> from Getopt::Long::Descriptive,
after the first.)
If not overridden, it returns an empty list.
=head2 validate_args
$command_plugin->validate_args(\%opt, \@args);
This method is passed a hashref of command line options (as processed by
Getopt::Long::Descriptive) and an arrayref of leftover arguments. It may throw
an exception (preferably by calling C<usage_error>, below) if they are invalid,
or it may do nothing to allow processing to continue.
=head2 usage_error
$self->usage_error("This command must not be run by root!");
This method should be called to die with human-friendly usage output, during
C<validate_args>.
lib/App/Cmd/Simple.pm view on Meta::CPAN
#pod
#pod If not overridden, it returns something that prints out like:
#pod
#pod yourapp [-?h] [long options...]
#pod
#pod =head2 validate_args
#pod
#pod $cmd->validate_args(\%opt, \@args);
#pod
#pod This method is passed a hashref of command line options (as processed by
#pod Getopt::Long::Descriptive) and an arrayref of leftover arguments. It may throw
#pod an exception (preferably by calling C<usage_error>) if they are invalid, or it
#pod may do nothing to allow processing to continue.
#pod
#pod =head2 execute
#pod
#pod Your::App::Cmd::Simple->execute(\%opt, \@args);
#pod
#pod This method does whatever it is the command should do! It is passed a hash
#pod reference of the parsed command-line options and an array reference of left
#pod over arguments.
lib/App/Cmd/Simple.pm view on Meta::CPAN
If not overridden, it returns something that prints out like:
yourapp [-?h] [long options...]
=head2 validate_args
$cmd->validate_args(\%opt, \@args);
This method is passed a hashref of command line options (as processed by
Getopt::Long::Descriptive) and an arrayref of leftover arguments. It may throw
an exception (preferably by calling C<usage_error>) if they are invalid, or it
may do nothing to allow processing to continue.
=head2 execute
Your::App::Cmd::Simple->execute(\%opt, \@args);
This method does whatever it is the command should do! It is passed a hash
reference of the parsed command-line options and an array reference of left
over arguments.
lib/App/Cmd/Tester.pm view on Meta::CPAN
#pod This will locally set C<@ARGV> to simulate command line arguments, and will
#pod then call the C<run> method on the given application class (or application).
#pod Output to the standard output and standard error filehandles will be captured.
#pod
#pod C<$result> is an App::Cmd::Tester::Result object, which has methods to access
#pod the following data:
#pod
#pod stdout - the output sent to stdout
#pod stderr - the output sent to stderr
#pod output - the combined output of stdout and stderr
#pod error - the exception thrown by running the application, or undef
#pod run_rv - the return value of the run method (generally irrelevant)
#pod exit_code - the numeric exit code that would've been issued (0 is 'okay')
#pod
#pod The output is captured using L<IO::TieCombine>, which I<can> ensure that the
#pod ordering is preserved in the combined output, but I<can't> capture the output
#pod of external programs. You can reverse these tradeoffs by using
#pod L<App::Cmd::Tester::CaptureExternal> instead.
#pod
#pod =cut
lib/App/Cmd/Tester.pm view on Meta::CPAN
use Sub::Exporter -setup => {
exports => { test_app => curry_method },
groups => { default => [ qw(test_app) ] },
};
our $TEST_IN_PROGRESS;
BEGIN {
*CORE::GLOBAL::exit = sub {
my ($rc) = @_;
return CORE::exit($rc) unless $TEST_IN_PROGRESS;
App::Cmd::Tester::Exited->throw($rc);
};
}
#pod =for Pod::Coverage result_class
#pod
#pod =cut
sub result_class { 'App::Cmd::Tester::Result' }
sub test_app {
lib/App/Cmd/Tester.pm view on Meta::CPAN
Sub::Install::install_sub({
code => sub { $_[0]->{$attr} },
as => $attr,
});
}
}
{
package App::Cmd::Tester::Exited 0.337;
sub throw {
my ($class, $code) = @_;
$code = 0 unless defined $code;
my $self = (bless \$code => $class);
die $self;
}
}
1;
__END__
lib/App/Cmd/Tester.pm view on Meta::CPAN
This will locally set C<@ARGV> to simulate command line arguments, and will
then call the C<run> method on the given application class (or application).
Output to the standard output and standard error filehandles will be captured.
C<$result> is an App::Cmd::Tester::Result object, which has methods to access
the following data:
stdout - the output sent to stdout
stderr - the output sent to stderr
output - the combined output of stdout and stderr
error - the exception thrown by running the application, or undef
run_rv - the return value of the run method (generally irrelevant)
exit_code - the numeric exit code that would've been issued (0 is 'okay')
The output is captured using L<IO::TieCombine>, which I<can> ensure that the
ordering is preserved in the combined output, but I<can't> capture the output
of external programs. You can reverse these tradeoffs by using
L<App::Cmd::Tester::CaptureExternal> instead.
=for Pod::Coverage result_class
( run in 0.266 second using v1.01-cache-2.11-cpan-496ff517765 )