CPANPL...:HOWTO(3pm)
π CPANPLUS::Shell::Default::Plugins::HOWTO π
okay bestie, pull up a chair β this is the CPANPLUS::Shell::Default::Plugins::HOWTO page from the User Contributed Perl Documentation, section 3pm. It's the whole tea on writing your own plugins for CPANPLUS::Shell::Default. β¨
πΈ NAME πΈ
CPANPLUS::Shell::Default::Plugins::HOWTO β literally the documentation on how to write your own plugins. That's it, that's the name, no notes. π
π¦ SYNOPSIS π¦
package CPANPLUS::Shell::Default::Plugins::MyPlugin;
### return command => method mapping
sub plugins { ( myplugin1 => 'mp1', myplugin2 => 'mp2' ) }
### method called when the command '/myplugin1' is issued
sub mp1 { .... }
### method called when the command '/? myplugin1' is issued
sub mp1_help { return "Help Text" }
π DESCRIPTION π
This pod text explains how to write your own plugins for CPANPLUS::Shell::Default. It's giving tutorial energy, and honestly? We ate. π₯
π HOWTO π
β¨ Registering Plugin Modules β¨
Plugins get detected using Module::Pluggable. Every single module living in the CPANPLUS::Shell::Default::Plugins::* namespace counts as a plugin, and the shell will try to load it. no cap.
So therefor: any plugin of yours must be declared in that namespace, inside a matching .pm file. That's the vibe check. π«Ά
π Registering Plugin Commands π
To register plugin commands, your package needs a plugins method, and it has to return a list of key/value pairs. The keys are the commands you wanna register. The values are the methods in your plugin package that get called when someone issues that command.
For example, a simple 'Hello, World!' plugin:
package CPANPLUS::Shell::Default::Plugins::HW;
sub plugins { return ( helloworld => 'hw' ) };
sub hw { print "Hello, world!\n" }
So when the user in the default shell issues the /helloworld command, that command gets dispatched to the plugin, and its hw method gets called. iconic behavior, honestly. π
π Registering Plugin Help π
Wanna give usage info for your plugin? The user of the default shell can type /? PLUGIN_COMMAND, and in that case the function PLUGIN_COMMAND_help gets called in your plugin package. iykyk.
For example, extending the above example, when a user calls /? helloworld, the function hw_help gets called, which might look like this:
sub hw_help { " /helloworld # prints "Hello, world!\n" }
If you don't provide a corresponding _help function for your commands, the default shell will handle it gracefully β but the user will be stuck with zero usage information on your commands. So omitting the help functions is considered undesirable. don't do that to them bestie π
π§ Arguments to Plugin Commands π§
Any plugin function receives the following arguments when it's called, and they are all positional. Positional means order matters, so keep track, okay? π
Classnameβ The name of your plugin classShellβ TheCPANPLUS::Shell::DefaultobjectBackendβ TheCPANPLUS::BackendobjectCommandβ The command issued by the userInputβ The input string from the userOptionsβ A hashref of options provided by the user
For example, the following command:
/helloworld bob --nofoo --bar=2 joe
Would yield the following arguments:
sub hw {
my $class = shift; # CPANPLUS::Shell::Default::Plugins::HW
my $shell = shift; # CPANPLUS::Shell::Default object
my $cb = shift; # CPANPLUS::Backend object
my $cmd = shift; # 'helloworld'
my $input = shift; # 'bob joe'
my $opts = shift; # { foo => 0, bar => 2 }
....
}
see how --nofoo becomes foo => 0 and --bar=2 becomes bar => 2? the options hashref is doing the most and we love her for it. π
π BUG REPORTS π
Please report bugs or other issues to <bug-cpanplus@rt.cpan.org<gt>. π«Ά
ngl if something's broken, tell the humans, not the void. π
βοΈ AUTHOR βοΈ
This module by Jos Boumans <kane@cpan.org>. main character energy. π
Β©οΈ COPYRIGHT Β©οΈ
The CPAN++ interface (of which this module is a part of) is copyright (c) 2001 - 2007, Jos Boumans <kane@cpan.org>. All rights reserved.
This library is free software; you may redistribute and/or modify it under the same terms as Perl itself. slay, open source. π
π SEE ALSO π
CPANPLUS::Shell::DefaultCPANPLUS::Shellcpanp
and that's the whole page bestie, go forth and write plugins π
β¨ this page is from perl v5.40.1, dated 2025-03-01, in the User Contributed Perl Documentation, section 3pm β and it's been CPANPL...:HOWTO(3pm) the entire time. mwah. π π π¦ β¨
π¦ where this page comes from
- debian trixie: libcpanplus-perl 0.9916-1 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu resolute: libcpanplus-perl 0.9916-1 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu stonking: libcpanplus-perl 0.9916-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