App::CLI(3pm)
π NAME π
App::CLI β the dispatcher module for command line interface programs. Youβre on the App::CLI(3pm) page, bestie. π
β¨ SYNOPSIS β¨
Okay so hereβs the whole group-chat receipt β literal code, typos and all, so donβt come for me:
package MyApp;
use base 'App::CLI'; # the DISPATCHER of your App
# it's not necessary putting the dispather
# on the top level of your App
package main;
MyApp->dispatch; # call dispather in where you want
package MyApp::List;
use base qw(App::CLI::Command); # any (SUB)COMMAND of your App
use constant options => (
"h|help" => "help",
"verbose" => "verbose",
'n|name=s' => 'name',
);
use constant subcommands => qw(User Nickname type); # if you want subcommands
# automatically dispatch to subcommands
# when invoke $ myapp list [user|nickname|--type]
# note 'type' lower case in first char
# is subcommand of old genre which is deprecated
sub run {
my ($self, @args) = @_;
print "verbose" if $self->{verbose};
my $name = $self->{name}; # get arg following long option --name
if ($self->{help}) {
# if $ myapp list --help or $ $ myapp list -h
# just only output PODs
} else {
# do something when imvoking $ my app list
# without subcommand and --help
}
}
package MyApp::List::User;
use base qw(App::CLI::Command);
use constant options => (
"h|help" => "help",
);
sub run {
my ($self,@args) = @_;
# code for listing user
}
pakcage MyApp::List::Nickname;
use base qw(App::CLI::Command);
use constant options => (
"sort=s" => "sort",
);
sub run {
my ($self,@args) = @_;
# code for listing nickname
}
package MyApp::List::type; # old genre of subcommand could not be cascading infinitely
use base qw(MyApp::List); # should inherit its parents command
sub run {
my ($self, @args);
# run to here when invoking $ myapp list --type
}
package MyApp::Help;
use base 'App::CLI::Command::Help';
use constant options => (
'verbose' => 'verbose',
);
sub run {
my ($self, @arg) = @_;
# do something
$self->SUPER(@_); # App::CLI::Command::Help would output PDOs of each command
}
π¦ DESCRIPTION π¦
App::CLI dispatches CLI (command line interface) based commands into command classes. It also supports subcommand and per-command options. iconic behavior. β¨
πΈ get_opt([@config], %opt_map) πΈ
Give it an options map, and it gets processed by Getopt::Long::Parser. Cute.
π¦ interface of dispatcher π¦
cmd_map($cmd)β find package name of subcommand in constant%alias. If itβs finded, returnucfirstof the package name; otherwise, returnucfirstof$cmditself.get_cmd($cmd, @arg)β return subcommand of first level via$ARGV[0].
π SEE ALSO π
App::CLI::CommandGetopt::Long
π AUTHORS π
Chia-liang Kao <clkao@clkao.org>Cornelius Lin <cornelius.howl@gmail.com>shelling <navyblueshellingford@gmail.com>
π COPYRIGHT π
Copyright 2005-2006 by Chia-liang Kao <clkao@clkao.org>.
This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
See <http://www.perl.com/perl/misc/Artistic.html>.
π Thatβs the whole page, bestie β sourced from perl v5.36.0, dated 2022-10-15. Mwah! π
π¦ where this page comes from
- ubuntu noble: libapp-cli-perl 0.313-4 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu resolute: libapp-cli-perl 0.313-4 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu stonking: libapp-cli-perl 0.313-4 Β· Artistic-1.0-Perl 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