Commandable::Finder::Packages(3pm) | User Contributed Perl Documentation | Commandable::Finder::Packages(3pm) |
"Commandable::Finder::Packages" - find commands stored per package
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 ) { ... }
This implementation of Commandable::Finder looks for implementations of commands, where each command is implemented by a different package somewhere in the symbol table.
This class uses Module::Pluggable to load packages from the filesystem. As commands are located per package (and not per file), the application can provide special-purpose internal commands by implementing more packages in the given namespace, regardless of which files they come from.
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) within each package. Often the constant pragma module is used to create them.
The following constant names are used by default:
use constant COMMAND_NAME => "name";
Gives a string name for the command.
use constant COMMAND_DESC => "description";
Gives a string description for the command.
use constant COMMAND_ARGS => ( { name => "argname", description => "description" }, );
Gives a list of command argument specifications. Each specification is a HASH reference corresponding to one positional argument, and should contain keys named "name", "description", and optionally "optional".
use constant COMMAND_OPTS => ( { name => "optname", description => "description" }, );
Gives a list of command option specifications. Each specification is a HASH reference giving one named option, in no particular order, and should contain keys named "name", "description" and optionally "mode" and "default".
$finder = Commandable::Finder::Packages->new( %args )
Constructs a new instance of "Commandable::Finder::Packages".
Takes the following named arguments:
If either name or description method are missing from a package, that package is silently ignored.
Any additional arguments are passed to the "configure" method to be used as configuration options.
Paul Evans <leonerd@leonerd.org.uk>
2023-01-08 | perl v5.36.0 |