Debian Codegraph @

README

raw
1 NAME
2 Class::Pluggable - Simple pluggable class.
3
4 SYNOPSIS
5 use Class::Pluggable;
6 use base qw(Class::Pluggable);
7
8 # Some::Plugin::Module has sub routin called newAction
9 addPlugin("Some::Plugin::Module");
10
11 newAction(); # Plugged action.
12
13 DESCRIPTION
14 This class makes your class (sub class of Class::Pluggable) pluggable.
15 In this documentatin, the word "pluggable" has two meanings.
16
17 One is just simply adding new method to your pluggable classs from other
18 plugin modules. So, after you plugged some modules to your class, you
19 can use there method exactly same as your own object method.
20
21 You can see this kind of plugin mechanism in CGI::Application and
22 CGI::Application::Plugin::Session.
23
24 There are one thing that Plugin developer have to know. The plugin
25 module MUST have @EXPORT_AS_PLUGIN to use this pluggable mechanism. This
26 works almost same as @EXPORT. But the methods in the @EXPORT_AS_PLUGIN
27 wouldn't be exported to your package. But it would be exported to the
28 subclass of Class::Pluggable (only when you call addPlugin()).
29
30 And the another meaning of "pluggable" is so called hook-mechanism. For
31 example, if you want to allow to other modules to do something before
32 and/or after some action. You can do like this:
33
34 $self->executePluginMethod($_, "before_action")
35 foreach $self->getPlugins();
36
37 ## do some your own action here.
38
39 $self->executePluginMethod($_, "after_action")
40 foreach $self->getPlugins();
41
42 METHODS
43 Here are all methods of Class::Pluggable.
44
45 addPlugin
46 YourClass->addPlugin($pluginName)
47
48 This will add new plugin to your class. What you added to here would
49 be returned by getPlugins() method.
50
51 getPlugins
52 @plugins = YourClass->getPlugins();
53
54 It will return all of plugin names that are already added to
55 YouClass.
56
57 executePluginMethod
58 $result = YourClass->executePluginMethod("SomePlugin", "someMethod");
59
60 This will execute the method someMethod of SomePlugin.
61
62 executeAllPluginMethod
63 YourClass->executeAllPluginMethod("someMethod");
64
65 This will execute the method someMethod of all plugin we have. This
66 is almost same as following code.
67
68 $self->executePluginMethod($_, "someMethod")
69 foreach $self->getPlugins();
70
71 The difference is executeAllPluginMethod can't return any values.
72 But executePluginMethod can.
73
74 addHook
75 YourClass->addHook("pre-init", "pre_init");
76
77 This will add new hook to your class. Whenever runHook("pre-init")
78 has called, the method pre_init of all plugins which we have will be
79 executed.
80
81 runHook
82 YourClass->runHook("pre-init");
83
84 This will execute the hook-method of all plugins which we have.
85
86 deleteHook
87 YourClass->deleteHook("pre-init");
88
89 This will delete the hook from YourClass. After calling this method,
90 you cannot call runHook("pre-init"). If you do, it will die
91 immediately.
92
93 SEE ALSO
94 ...
95
96 AUTHOR
97 Ken Takeshige, <[email protected]>
98
99 COPYRIGHT AND LICENSE
100 Copyright (C) 2006 by Ken Takeshige
101
102 This library is free software; you can redistribute it and/or modify
103 it under the same terms as Perl itself, either Perl version 5.8.6
104 or, at your option, any later version of Perl 5 you may have
105 available.
106