1 .\" Automatically generated by Pod::Man v1.37, Pod::Parser v1.3
4 .\" ========================================================================
5 .de Sh \" Subsection heading
13 .de Sp \" Vertical space (when we can't use .PP)
17 .de Vb \" Begin verbatim text
22 .de Ve \" End verbatim text
26 .\" Set up some character translations and predefined strings. \*(-- will
27 .\" give an unbreakable dash, \*(PI will give pi, \*(L" will give a left
28 .\" double quote, and \*(R" will give a right double quote. | will give a
29 .\" real vertical bar. \*(C+ will give a nicer C++. Capital omega is used to
30 .\" do unbreakable dashes and therefore won't be available. \*(C` and \*(C'
31 .\" expand to `' in nroff, nothing in troff, for use with C<>.
33 .ds C+ C\v'-.1v'\h'-1p'\s-2+\h'-1p'+\s0\v'.1v'\h'-1p'
37 . if (\n(.H=4u)&(1m=24u) .ds -- \(*W\h'-12u'\(*W\h'-12u'-\" diablo 10 pitch
38 . if (\n(.H=4u)&(1m=20u) .ds -- \(*W\h'-12u'\(*W\h'-8u'-\" diablo 12 pitch
51 .\" If the F register is turned on, we'll generate index entries on stderr for
52 .\" titles (.TH), headers (.SH), subsections (.Sh), items (.Ip), and index
53 .\" entries marked with X<> in POD. Of course, you'll have to process the
54 .\" output yourself in some meaningful fashion.
57 . tm Index:\\$1\t\\n%\t"\\$2"
63 .\" For nroff, turn off justification. Always turn off hyphenation; it makes
64 .\" way too many mistakes in technical documents.
68 .\" Accent mark definitions (@(#)ms.acc 1.5 88/02/08 SMI; from UCB 4.2).
69 .\" Fear. Run. Save yourself. No user-serviceable parts.
70 . \" fudge factors for nroff and troff
79 . ds #H ((1u-(\\\\n(.fu%2u))*.13m)
85 . \" simple accents for nroff and troff
95 . ds ' \\k:\h'-(\\n(.wu*8/10-\*(#H)'\'\h"|\\n:u"
96 . ds ` \\k:\h'-(\\n(.wu*8/10-\*(#H)'\`\h'|\\n:u'
97 . ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'^\h'|\\n:u'
98 . ds , \\k:\h'-(\\n(.wu*8/10)',\h'|\\n:u'
99 . ds ~ \\k:\h'-(\\n(.wu-\*(#H-.1m)'~\h'|\\n:u'
100 . ds / \\k:\h'-(\\n(.wu*8/10-\*(#H)'\z\(sl\h'|\\n:u'
102 . \" troff and (daisy-wheel) nroff accents
103 .ds : \\k:\h'-(\\n(.wu*8/10-\*(#H+.1m+\*(#F)'\v'-\*(#V'\z.\h'.2m+\*(#F'.\h'|\\n:u'\v'\*(#V'
104 .ds 8 \h'\*(#H'\(*b\h'-\*(#H'
105 .ds o \\k:\h'-(\\n(.wu+\w'\(de'u-\*(#H)/2u'\v'-.3n'\*(#[\z\(de\v'.3n'\h'|\\n:u'\*(#]
106 .ds d- \h'\*(#H'\(pd\h'-\w'~'u'\v'-.25m'\f2\(hy\fP\v'.25m'\h'-\*(#H'
107 .ds D- D\\k:\h'-\w'D'u'\v'-.11m'\z\(hy\v'.11m'\h'|\\n:u'
108 .ds th \*(#[\v'.3m'\s+1I\s-1\v'-.3m'\h'-(\w'I'u*2/3)'\s-1o\s+1\*(#]
109 .ds Th \*(#[\s+2I\s-2\h'-\w'I'u*3/5'\v'-.3m'o\v'.3m'\*(#]
110 .ds ae a\h'-(\w'a'u*4/10)'e
111 .ds Ae A\h'-(\w'A'u*4/10)'E
112 . \" corrections for vroff
113 .if v .ds ~ \\k:\h'-(\\n(.wu*9/10-\*(#H)'\s-2\u~\d\s+2\h'|\\n:u'
114 .if v .ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'\v'-.4m'^\v'.4m'\h'|\\n:u'
115 . \" for low resolution devices (crt and lpr)
116 .if \n(.H>23 .if \n(.V>19 \
129 .\" ========================================================================
131 .IX Title "Module::Pluggable 3"
132 .TH Module::Pluggable 3 "2009-03-02" "perl v5.8.7" "User Contributed Perl Documentation"
134 Module::Pluggable \- automatically give your module the ability to have plugins
136 .IX Header "SYNOPSIS"
137 Simple use Module::Pluggable \-
141 \& use Module::Pluggable;
148 \& my $mc = MyClass\->new();
149 \& # returns the names of all plugins installed under MyClass::Plugin::*
150 \& my @plugins = $mc\->plugins();
154 Why would you want to do this? Say you have something that wants to pass an
155 object to a number of different plugins in turn. For example you may
156 want to extract meta-data from every email you get sent and do something
157 with it. Plugins make sense here because then you can keep adding new
158 meta data parsers and all the logic and docs for each one will be
159 self contained and new handlers are easy to add without changing the
160 core code. For that, you might do something like ...
163 \& package Email::Examiner;
168 \& use Email::Simple;
169 \& use Module::Pluggable require => 1;
173 \& sub handle_email {
175 \& my $email = shift;
179 \& foreach my $plugin ($self\->plugins) {
180 \& $plugin\->examine($email);
189 \&.. and all the plugins will get a chance in turn to look at it.
191 This can be trivally extended so that plugins could save the email
192 somewhere and then no other plugin should try and do that.
193 Simply have it so that the \f(CW\*(C`examine\*(C'\fR method returns \f(CW1\fR if
194 it has saved the email somewhere. You might also wnat to be paranoid
195 and check to see if the plugin has an \f(CW\*(C`examine\*(C'\fR method.
198 \& foreach my $plugin ($self\->plugins) {
199 \& next unless $plugin\->can('examine');
200 \& last if $plugin\->examine($email);
204 And so on. The sky's the limit.
206 .IX Header "DESCRIPTION"
207 Provides a simple but, hopefully, extensible way of having 'plugins' for
208 your module. Obviously this isn't going to be the be all and end all of
209 solutions but it works for me.
211 Essentially all it does is export a method into your namespace that
212 looks through a search path for .pm files and turn those into class names.
214 Optionally it instantiates those classes for you.
216 .IX Header "ADVANCED USAGE"
217 Alternatively, if you don't want to use 'plugins' as the method ...
221 \& use Module::Pluggable sub_name => 'foo';
227 \& my @plugins = $mc\->foo();
230 Or if you want to look in another namespace
234 \& use Module::Pluggable search_path => ['Acme::MyClass::Plugin', 'MyClass::Extend'];
240 \& use Module::Pluggable search_dirs => ['mylibs/Foo'];
243 Or if you want to instantiate each plugin rather than just return the name
247 \& use Module::Pluggable instantiate => 'new';
253 \& # whatever is passed to 'plugins' will be passed
254 \& # to 'new' for each plugin
255 \& my @plugins = $mc\->plugins(@options);
258 alternatively you can just require the module without instantiating it
262 \& use Module::Pluggable require => 1;
265 since requiring automatically searches inner packages, which may not be desirable, you can turn this off
269 \& use Module::Pluggable require => 1, inner => 0;
272 You can limit the plugins loaded using the except option, either as a string,
277 \& use Module::Pluggable except => 'MyClass::Plugin::Foo';
284 \& use Module::Pluggable except => ['MyClass::Plugin::Foo', 'MyClass::Plugin::Bar'];
291 \& use Module::Pluggable except => qr/^MyClass::Plugin::(Foo|Bar)$/;
294 and similarly for only which will only load plugins which match.
296 Remember you can use the module more than once
300 \& use Module::Pluggable search_path => 'MyClass::Filters' sub_name => 'filters';
301 \& use Module::Pluggable search_path => 'MyClass::Plugins' sub_name => 'plugins';
307 \& my @filters = $self\->filters;
308 \& my @plugins = $self\->plugins;
311 .IX Header "INNER PACKAGES"
312 If you have, for example, a file \fBlib/Something/Plugin/Foo.pm\fR that
313 contains package definitions for both \f(CW\*(C`Something::Plugin::Foo\*(C'\fR and
314 \&\f(CW\*(C`Something::Plugin::Bar\*(C'\fR then as long as you either have either
315 the \fBrequire\fR or \fBinstantiate\fR option set then we'll also find
316 \&\f(CW\*(C`Something::Plugin::Bar\*(C'\fR. Nifty!
319 You can pass a hash of options when importing this module.
321 The options can be ...
323 .IX Subsection "sub_name"
324 The name of the subroutine to create in your namespace.
326 By default this is 'plugins'
328 .IX Subsection "search_path"
329 An array ref of namespaces to look in.
331 .IX Subsection "search_dirs"
332 An array ref of directorys to look in before \f(CW@INC\fR.
334 .IX Subsection "instantiate"
335 Call this method on the class. In general this will probably be 'new'
336 but it can be whatever you want. Whatever arguments are passed to 'plugins'
337 will be passed to the method.
339 The default is 'undef' i.e just return the class name.
341 .IX Subsection "require"
342 Just require the class, don't instantiate (overrides 'instantiate');
344 .IX Subsection "inner"
345 If set to 0 will \fBnot\fR search inner packages.
346 If set to 1 will override \f(CW\*(C`require\*(C'\fR.
348 .IX Subsection "only"
349 Takes a string, array ref or regex describing the names of the only plugins to
350 return. Whilst this may seem perverse ... well, it is. But it also
351 makes sense. Trust me.
353 .IX Subsection "except"
354 Similar to \f(CW\*(C`only\*(C'\fR it takes a description of plugins to exclude
355 from returning. This is slightly less perverse.
357 .IX Subsection "package"
358 This is for use by extension modules which build on \f(CW\*(C`Module::Pluggable\*(C'\fR:
359 passing a \f(CW\*(C`package\*(C'\fR option allows you to place the plugin method in a
360 different package other than your own.
362 .IX Subsection "file_regex"
363 By default \f(CW\*(C`Module::Pluggable\*(C'\fR only looks for \fI.pm\fR files.
365 By supplying a new \f(CW\*(C`file_regex\*(C'\fR then you can change this behaviour e.g
368 \& file_regex => qr/\e.plugin$/
370 .Sh "include_editor_junk"
371 .IX Subsection "include_editor_junk"
372 By default \f(CW\*(C`Module::Pluggable\*(C'\fR ignores files that look like they were
373 left behind by editors. Currently this means files ending in \fI~\fR (~),
374 the extensions \fI.swp\fR or \fI.swo\fR, or files beginning with \fI.#\fR.
376 Setting \f(CW\*(C`include_editor_junk\*(C'\fR changes \f(CW\*(C`Module::Pluggable\*(C'\fR so it does
377 not ignore any files it finds.
381 .IX Subsection "search_path"
382 The method \f(CW\*(C`search_path\*(C'\fR is exported into you namespace as well.
383 You can call that at any time to change or replace the
387 \& $self\->search_path( add => "New::Path" ); # add
388 \& $self\->search_path( new => "New::Path" ); # replace
391 .IX Header "FUTURE PLANS"
392 This does everything I need and I can't really think of any other
393 features I want to add. Famous last words of course
395 Recently tried fixed to find inner packages and to make it
396 \&'just work' with \s-1PAR\s0 but there are still some issues.
398 However suggestions (and patches) are welcome.
401 Simon Wistow <simon@thegestalt.org>
404 Copyright, 2006 Simon Wistow
406 Distributed under the same terms as Perl itself.
411 .IX Header "SEE ALSO"
412 File::Spec, File::Find, File::Basename, Class::Factory::Util, Module::Pluggable::Ordered