.\" Automatically generated by Pod::Man 4.14 (Pod::Simple 3.40) .\" .\" Standard preamble: .\" ======================================================================== .de Sp \" Vertical space (when we can't use .PP) .if t .sp .5v .if n .sp .. .de Vb \" Begin verbatim text .ft CW .nf .ne \\$1 .. .de Ve \" End verbatim text .ft R .fi .. .\" Set up some character translations and predefined strings. \*(-- will .\" give an unbreakable dash, \*(PI will give pi, \*(L" will give a left .\" double quote, and \*(R" will give a right double quote. \*(C+ will .\" give a nicer C++. Capital omega is used to do unbreakable dashes and .\" therefore won't be available. \*(C` and \*(C' expand to `' in nroff, .\" nothing in troff, for use with C<>. .tr \(*W- .ds C+ C\v'-.1v'\h'-1p'\s-2+\h'-1p'+\s0\v'.1v'\h'-1p' .ie n \{\ . ds -- \(*W- . ds PI pi . if (\n(.H=4u)&(1m=24u) .ds -- \(*W\h'-12u'\(*W\h'-12u'-\" diablo 10 pitch . if (\n(.H=4u)&(1m=20u) .ds -- \(*W\h'-12u'\(*W\h'-8u'-\" diablo 12 pitch . ds L" "" . ds R" "" . ds C` "" . ds C' "" 'br\} .el\{\ . ds -- \|\(em\| . ds PI \(*p . ds L" `` . ds R" '' . ds C` . ds C' 'br\} .\" .\" Escape single quotes in literal strings from groff's Unicode transform. .ie \n(.g .ds Aq \(aq .el .ds Aq ' .\" .\" If the F register is >0, we'll generate index entries on stderr for .\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index .\" entries marked with X<> in POD. Of course, you'll have to process the .\" output yourself in some meaningful fashion. .\" .\" Avoid warning from groff about undefined register 'F'. .de IX .. .nr rF 0 .if \n(.g .if rF .nr rF 1 .if (\n(rF:(\n(.g==0)) \{\ . if \nF \{\ . de IX . tm Index:\\$1\t\\n%\t"\\$2" .. . if !\nF==2 \{\ . nr % 0 . nr F 2 . \} . \} .\} .rr rF .\" ======================================================================== .\" .IX Title "Class::Pluggable 3pm" .TH Class::Pluggable 3pm "2021-12-26" "perl v5.32.1" "User Contributed Perl Documentation" .\" For nroff, turn off justification. Always turn off hyphenation; it makes .\" way too many mistakes in technical documents. .if n .ad l .nh .SH "NAME" Class::Pluggable \- Simple pluggable class. .SH "SYNOPSIS" .IX Header "SYNOPSIS" .Vb 2 \& use Class::Pluggable; \& use base qw(Class::Pluggable); \& \& # Some::Plugin::Module has sub routin called newAction \& add_plugin("Some::Plugin::Module"); \& \& newAction(); # Plugged action. .Ve .SH "DESCRIPTION" .IX Header "DESCRIPTION" This class makes your class (sub class of Class::Pluggable) pluggable. In this documentatin, the word \*(L"pluggable\*(R" has two meanings. .PP One is just simply adding new method to your pluggable classs from other plugin modules. So, after you plugged some modules to your class, you can use there method exactly same as your own object method. .PP You can see this kind of plugin mechanism in CGI::Application and CGI::Application::Plugin::Session. .PP There are one thing that Plugin developer have to know. The plugin module \s-1MUST\s0 have \f(CW@EXPORT_AS_PLUGIN\fR to use this pluggable mechanism. This works almost same as \f(CW@EXPORT\fR. But the methods in the \&\f(CW@EXPORT_AS_PLUGIN\fR wouldn't be exported to your package. But it would be exported to the subclass of Class::Pluggable (only when you call \fBadd_plugin()\fR). .PP And the another meaning of \*(L"pluggable\*(R" is so called hook-mechanism. For example, if you want to allow to other modules to do something before and/or after some action. You can do like this: .PP .Vb 2 \& $self\->execute_plugin_method($_, "before_action") \& foreach $self\->get_plugins(); \& \& ## do some your own action here. \& \& $self\->execute_plugin_method($_, "after_action") \& foreach $self\->get_plugins(); .Ve .SH "METHODS" .IX Header "METHODS" Here are all methods of Class::Pluggable. .IP "add_plugin" 4 .IX Item "add_plugin" .Vb 1 \& $object\->add_plugin($pluginName) .Ve .Sp This will add new plugin to your class. What you added to here would be returned by \fBget_plugins()\fR method. .IP "get_plugins" 4 .IX Item "get_plugins" .Vb 1 \& @plugins = $object\->get_plugins(); .Ve .Sp It will return all of plugin names that are already added to YouClass. .IP "execute_plugin_method" 4 .IX Item "execute_plugin_method" .Vb 1 \& $result = $object\->execute_plugin_method("SomePlugin", "someMethod"); .Ve .Sp This will execute the method someMethod of SomePlugin. .IP "execute_all_plugin_method" 4 .IX Item "execute_all_plugin_method" .Vb 1 \& $object\->execute_all_plugin_method("someMethod"); .Ve .Sp This will execute the method someMethod of all plugin we have. This is almost same as following code. .Sp .Vb 2 \& $self\->execute_plugin_method($_, "someMethod") \& foreach $self\->get_plugins(); .Ve .Sp The difference is executeAllPluginMethod can't return any values. But executePluginMethod can. .IP "add_hook" 4 .IX Item "add_hook" .Vb 1 \& $object\->add_hook("pre\-init", "pre_init"); .Ve .Sp This will add new hook to your class. Whenever run_hook(\*(L"pre\-init\*(R") has called, the method pre_init of all plugins which we have will be executed. .IP "run_hook" 4 .IX Item "run_hook" .Vb 1 \& $object\->run_hook("pre\-init"); .Ve .Sp This will execute the hook-method of all plugins which we have. .IP "remove_hook" 4 .IX Item "remove_hook" .Vb 1 \& $object\->remove_hook("pre\-init"); .Ve .Sp This will delete the hook from YourClass. After calling this method, you cannot call run_hook(\*(L"pre\-init\*(R"). If you do, it will die immediately. .SH "SEE ALSO" .IX Header "SEE ALSO" \&... .SH "AUTHOR" .IX Header "AUTHOR" Ken Takeshige, .SH "COPYRIGHT AND LICENSE" .IX Header "COPYRIGHT AND LICENSE" Copyright (C) 2006 by Ken Takeshige .PP This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself, either Perl version 5.8.6 or, at your option, any later version of Perl 5 you may have available. .SH "POD ERRORS" .IX Header "POD ERRORS" Hey! \fBThe above document had some coding errors, which are explained below:\fR .IP "Around line 211:" 4 .IX Item "Around line 211:" You forgot a '=back' before '=head1'