1CPANPLUS::Shell::DefaulUts:e:rPlCuognitnrsi:b:uHtCOePWdATNOPP(eL3rU)lS:D:oSchuemleln:t:aDteifoanult::Plugins::HOWTO(3)
2
3
4

NAME

6       CPANPLUS::Shell::Default::Plugins::HOWTO -- documentation on how to
7       write your own plugins
8

SYNOPSIS

10           package CPANPLUS::Shell::Default::Plugins::MyPlugin;
11
12           ### return command => method mapping
13           sub plugins { ( myplugin1 => 'mp1', myplugin2 => 'mp2' ) }
14
15           ### method called when the command '/myplugin1' is issued
16           sub mp1 { .... }
17
18           ### method called when the command '/? myplugin1' is issued
19           sub mp1_help { return "Help Text" }
20

DESCRIPTION

22       This pod text explains how to write your own plugins for "CPAN‐
23       PLUS::Shell::Default".
24

HOWTO

26       Registering Plugin Modules
27
28       Plugins are detected by using "Module::Pluggable". Every module in the
29       "CPANPLUS::Shell::Default::Plugins::*" namespace is considered a plug‐
30       in, and is attempted to be loaded.
31
32       Therefor, any plugin must be declared in that namespace, in a corre‐
33       sponding ".pm" file.
34
35       Registering Plugin Commands
36
37       To register any plugin commands, a list of key value pairs must be
38       returned by a "plugins" method in your package. The keys are the com‐
39       mands you wish to register, the values are the methods in the plugin
40       package you wish to have called when the command is issued.
41
42       For example, a simple 'Hello, World!' plugin:
43
44           package CPANPLUS::Shell::Default::Plugins::HW;
45
46           sub plugins { return ( helloworld => 'hw' ) };
47
48           sub hw { print "Hello, world!\n" }
49
50       When the user in the default shell now issues the "/helloworld" com‐
51       mand, this command will be dispatched to the plugin, and it's "hw"
52       method will be called
53
54       Registering Plugin Help
55
56       To provide usage information for your plugin, the user of the default
57       shell can type "/? PLUGIN_COMMAND". In that case, the function "PLUG‐
58       IN_COMMAND_help" will be called in your plugin package.
59
60       For example, extending the above example, when a user calls "/? hel‐
61       loworld", the function "hw_help" will be called, which might look like
62       this:
63
64           sub hw_help { "    /helloworld      # prints "Hello, world!\n" }
65
66       If you dont provide a corresponding _help function to your commands,
67       the default shell will handle it gracefully, but the user will be stuck
68       without usage information on your commands, so it's considered undesir‐
69       able to omit the help functions.
70
71       Arguments to Plugin Commands
72
73       Any plugin function will receive the following arguments when called,
74       which are all positional:
75
76       Classname -- The name of your plugin class
77       Shell     -- The CPANPLUS::Shell::Default object
78       Backend   -- The CPANPLUS::Backend object
79       Command   -- The command issued by the user
80       Input     -- The input string from the user
81       Options   -- A hashref of options provided by the user
82
83       For example, the following command:
84
85           /helloworld bob --nofoo --bar=2 joe
86
87       Would yield the following arguments:
88
89           sub hw {
90               my $class   = shift;    # CPANPLUS::Shell::Default::Plugins::HW
91               my $shell   = shift;    # CPANPLUS::Shell::Default object
92               my $cb      = shift;    # CPANPLUS::Backend object
93               my $cmd     = shift;    # 'helloworld'
94               my $input   = shift;    # 'bob joe'
95               my $opts    = shift;    # { foo => 0, bar => 2 }
96
97               ....
98           }
99

BUG REPORTS

101       Please report bugs or other issues to <bug-cpanplus@rt.cpan.org<gt>.
102

AUTHOR

104       This module by Jos Boumans <kane@cpan.org>.
105
107       The CPAN++ interface (of which this module is a part of) is copyright
108       (c) 2001 - 2007, Jos Boumans <kane@cpan.org>. All rights reserved.
109
110       This library is free software; you may redistribute and/or modify it
111       under the same terms as Perl itself.
112

SEE ALSO

114       CPANPLUS::Shell::Default, CPANPLUS::Shell, cpanp
115
116
117
118perl v5.8.8                       20C0P7A-N0P3L-U3S1::Shell::Default::Plugins::HOWTO(3)
Impressum