3 CPANPLUS::Shell::Default::Plugins::HOWTO -- documentation on how to write your own plugins
7 package CPANPLUS::Shell::Default::Plugins::MyPlugin;
9 ### return command => method mapping
10 sub plugins { ( myplugin1 => 'mp1', myplugin2 => 'mp2' ) }
12 ### method called when the command '/myplugin1' is issued
15 ### method called when the command '/? myplugin1' is issued
16 sub mp1_help { return "Help Text" }
20 This pod text explains how to write your own plugins for
21 C<CPANPLUS::Shell::Default>.
25 =head2 Registering Plugin Modules
27 Plugins are detected by using C<Module::Pluggable>. Every module in
28 the C<CPANPLUS::Shell::Default::Plugins::*> namespace is considered a
29 plugin, and is attempted to be loaded.
31 Therefor, any plugin must be declared in that namespace, in a corresponding
34 =head2 Registering Plugin Commands
36 To register any plugin commands, a list of key value pairs must be returned
37 by a C<plugins> method in your package. The keys are the commands you wish
38 to register, the values are the methods in the plugin package you wish to have
39 called when the command is issued.
41 For example, a simple 'Hello, World!' plugin:
43 package CPANPLUS::Shell::Default::Plugins::HW;
45 sub plugins { return ( helloworld => 'hw' ) };
47 sub hw { print "Hello, world!\n" }
49 When the user in the default shell now issues the C</helloworld> command,
50 this command will be dispatched to the plugin, and its C<hw> method will
53 =head2 Registering Plugin Help
55 To provide usage information for your plugin, the user of the default shell
56 can type C</? PLUGIN_COMMAND>. In that case, the function C<PLUGIN_COMMAND_help>
57 will be called in your plugin package.
59 For example, extending the above example, when a user calls C</? helloworld>,
60 the function C<hw_help> will be called, which might look like this:
62 sub hw_help { " /helloworld # prints "Hello, world!\n" }
64 If you dont provide a corresponding _help function to your commands, the
65 default shell will handle it gracefully, but the user will be stuck without
66 usage information on your commands, so it's considered undesirable to omit
69 =head2 Arguments to Plugin Commands
71 Any plugin function will receive the following arguments when called, which
76 =item Classname -- The name of your plugin class
78 =item Shell -- The CPANPLUS::Shell::Default object
80 =item Backend -- The CPANPLUS::Backend object
82 =item Command -- The command issued by the user
84 =item Input -- The input string from the user
86 =item Options -- A hashref of options provided by the user
90 For example, the following command:
92 /helloworld bob --nofoo --bar=2 joe
94 Would yield the following arguments:
97 my $class = shift; # CPANPLUS::Shell::Default::Plugins::HW
98 my $shell = shift; # CPANPLUS::Shell::Default object
99 my $cb = shift; # CPANPLUS::Backend object
100 my $cmd = shift; # 'helloworld'
101 my $input = shift; # 'bob joe'
102 my $opts = shift; # { foo => 0, bar => 2 }
110 Please report bugs or other issues to E<lt>bug-cpanplus@rt.cpan.org<gt>.
114 This module by Jos Boumans E<lt>kane@cpan.orgE<gt>.
118 The CPAN++ interface (of which this module is a part of) is copyright (c)
119 2001 - 2007, Jos Boumans E<lt>kane@cpan.orgE<gt>. All rights reserved.
121 This library is free software; you may redistribute and/or modify it
122 under the same terms as Perl itself.
126 L<CPANPLUS::Shell::Default>, L<CPANPLUS::Shell>, L<cpanp>
131 # c-indentation-style: bsd
133 # indent-tabs-mode: nil
135 # vim: expandtab shiftwidth=4: