Comman...ackages(3pm)
π Commandable::Finder::Packages β the finder that goes per-package π
okay bestie, so this is Commandable::Finder::Packages, a Perl module living in the User Contributed Perl Documentation section (3pm). It's a finder that hunts down commands, and it does it per package, not per file. Let's get into it πΈ
β¨ NAME β¨
Commandable::Finder::Packages β find commands stored per package π
β¨ SYNOPSIS β¨
use Commandable::Finder::Packages;
my $finder = Commandable::Finder::Packages->new(
base => "MyApp::Command",
);
my $help_command = $finder->find_command( "help" );
foreach my $command ( $finder->find_commands ) {
...
}
β¨ DESCRIPTION β¨
so this implementation of Commandable::Finder is out here looking for implementations of commands, and the whole vibe is that each command is implemented by a different package somewhere in the symbol table. one command, one package, no cap π
It uses Module::Pluggable to load packages straight off the filesystem π¦. And because commands are located per package (not per file), the app can hand-craft special-purpose internal commands by just implementing more packages in the given namespace β doesn't matter which files they came from, honestly iconic.
β¨ CONSTANTS β¨
package My::App::Commands::example;
use constant COMMAND_NAME => "example";
use constant COMMAND_DESC => "an example of a command";
...
Properties about each command are stored as methods (usually constant methods) inside each package. Bestie, nine times out of ten it's the constant pragma module doing the heavy lifting to create them β¨
These are the constant names used by default:
π COMMAND_NAME π
use constant COMMAND_NAME => "name";
gives you a string name for the command π
π COMMAND_DESC π
use constant COMMAND_DESC => "description";
gives you a string description for the command π
π COMMAND_ARGS π
use constant COMMAND_ARGS => (
{ name => "argname", description => "description" },
);
gives you a list of command argument specifications. Each specification is a HASH reference corresponding to one positional argument, and it should contain keys named "name", "description", and optionally "optional". literally one hash per positional arg, in order, periodt π«Ά
π COMMAND_OPTS π
use constant COMMAND_OPTS => (
{ name => "optname", description => "description" },
);
gives you a list of command option specifications. Each specification is a HASH reference giving one named option, in no particular order (chaos is allowed, it's giving free spirit), and it should contain keys named "name", "description" and optionally "mode", "multi" and "default" β
β¨ CONSTRUCTOR β¨
π new π
$finder = Commandable::Finder::Packages->new( %args )
Constructs a brand-new instance of Commandable::Finder::Packages. Fresh out the box, slay π
Takes the following named arguments:
base => STRβ the base of the package namespace to look inside for packages that implement commands. this is your home base bestie πname_method => STRβ Optional. Gives the name of the method inside each command package to invoke to generate the name of the command. DefaultCOMMAND_NAME.description_method => STRβ Optional. Gives the name of the method inside each command package to invoke to generate the description text of the command. DefaultCOMMAND_DESC.arguments_method => STRβ Optional. Gives the name of the method inside each command package to invoke to generate a list of argument specifications. DefaultCOMMAND_ARGS.options_method => STRβ Optional. Gives the name of the method inside each command package to invoke to generate a list of option specifications. DefaultCOMMAND_OPTS.code_method => STRβ Optional. Gives the name of the method inside each command package which implements the actual command behaviour β you know, the part that does the thing. Defaultrun.named_by_package => BOOLβ Optional. If true, the name of each command will be taken from its package name, with the leadingbasestring removed. If absent or false, thename_methodwill be used instead. pick your fighter π€
Heads up bestie π¨ β if either the name method or the description method is missing from a package, that package gets silently ignored. no error, no warning, just ghosted π
Any additional arguments are passed along to the configure method to be used as configuration options. so like, extra stuff goes to configure, got it π
β¨ AUTHOR β¨
Paul Evans <leonerd@leonerd.org.uk> β the icon, the moment, the legend π
and that's the whole page, bestie!! written for perl v5.40.0, dated 2024-09-08, from the User Contributed Perl Documentation. go forth and let your packages find themselves πβ¨π¦
π¦ where this page comes from
- ubuntu resolute: libcommandable-perl 0.14-1 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu stonking: libcommandable-perl 0.14-1 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms