blib/lib/POE/Component/Server/IRC/Plugin.pm

filter: Statementstmt 100% 17 / 17 Branchbran n/a Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 4 / 4 Podpod n/a totaltotal 100% 21 / 21 CC 1 SCAR 0.0
CC
1
Cov
100%
BEGIN
1.0
BEGIN
1.0
BEGIN
1.0
CRAP 1.0
« bin/pmkpasswd ↑ Summary
1 package POE::Component::Server::IRC::Plugin;
2 180 $POE::Component::Server::IRC::Plugin::VERSION = '1.66';
3 180 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 180 ▶use warnings FATAL => 'all';
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 180 require Exporter;
7 180 ▶use base qw(Exporter);
Subroutine BEGIN: called CC=1 SCAR=0.0
8 180 our @EXPORT_OK = qw(PCSI_EAT_NONE PCSI_EAT_CLIENT PCSI_EAT_PLUGIN PCSI_EAT_ALL);
9 180 our %EXPORT_TAGS = ( ALL => [@EXPORT_OK] );
10  
11 180 ▶use constant {
Subroutine BEGIN: called CC=1 SCAR=0.0
12 180 PCSI_EAT_NONE => 1,
13 PCSI_EAT_CLIENT => 2,
14 PCSI_EAT_PLUGIN => 3,
15 PCSI_EAT_ALL => 4,
16 180 };
17  
18 180 1;
19  
20 =encoding utf8
21  
22 =head1 NAME
23  
24 POE::Component::Server::IRC::Plugin - Provides plugin documentation for
25 POE::Component::Server::IRC.
26  
27 =head1 DESCRIPTION
28  
29 This is the document coders/users should refer to when using/developing
30 plugins for POE::Component::Server::IRC.
31  
32 The plugin system works by letting coders hook into aspects of
33 POE::Component::Server::IRC::Backend. More details are found in the docs
34 for L<Object::Pluggable|Object::Pluggable>.
35  
36 The general architecture of using the plugins should be:
37  
38 # Import the stuff...
39 use POE;
40 use POE::Component::Server::IRC::Backend;
41 use POE::Component::Server::IRC::Plugin::ExamplePlugin;
42  
43 # Create our session here
44 POE::Session->create( ... );
45  
46 # Create the IRC session here
47 my $irc = POE::Component::Server::IRC::Backend->spawn() or die 'Nooo!';
48  
49 # Create the plugin
50 # Of course it could be something like $plugin = MyPlugin->new();
51 my $plugin = POE::Component::Server::IRC::Plugin::ExamplePlugin->new( ... );
52  
53 # Hook it up!
54 $irc->plugin_add( 'ExamplePlugin', $plugin );
55  
56 # OOPS, we lost the plugin object!
57 my $pluginobj = $irc->plugin_get( 'ExamplePlugin' );
58  
59 # We want a list of plugins and objects
60 my $hashref = $irc->plugin_list();
61  
62 # Oh! We want a list of plugin aliases.
63 my @aliases = keys %{ $irc->plugin_list() };
64  
65 # Ah, we want to remove the plugin
66 $plugin = $irc->plugin_del( 'ExamplePlugin' );
67  
68 The plugins themselves will conform to the standard API described here. What
69 they can do is limited only by imagination and the IRC RFC's ;)
70  
71 package POE::Component::Server::IRC::ExamplePlugin;
72  
73 # Import the constants
74 use POE::Component::Server::IRC::Plugin qw( :ALL );
75  
76 # Our constructor
77 sub new {
78 # ...
79 }
80  
81 # Required entry point for POE::Component::Server::IRC::Backend
82 sub PCSI_register {
83 my ($self, $irc) = @_;
84 # Register events we are interested in
85 $irc->plugin_register( $self, 'SERVER', qw(connection) );
86  
87 # Return success
88 return 1;
89 }
90  
91 # Required exit point for PoCo-Server-IRC
92 sub PCSI_unregister {
93 my ($self, $irc) = @_;
94  
95 # PCSIB will automatically unregister events for the plugin
96  
97 # Do some cleanup...
98  
99 # Return success
100 return 1;
101 }
102  
103 # Registered events will be sent to methods starting with IRC_
104 # If the plugin registered for SERVER - irc_355
105 sub IRCD_connection {
106 my ($self, $irc, $line) = @_;
107  
108 # Remember, we receive pointers to scalars, so we can modify them
109 $$line = 'frobnicate!';
110  
111 # Return an exit code
112 return PCSI_EAT_NONE;
113 }
114  
115 # Default handler for events that do not have a corresponding
116 # plugin method defined.
117 sub _default {
118 my ($self, $irc, $event) = splice @_, 0, 3;
119  
120 print "Default called for $event\n";
121  
122 # Return an exit code
123 return PCSI_EAT_NONE;
124 }
125  
126 =head2 Pipeline
127  
128 The plugins are given priority on a first come, first serve basis.
129 Therefore, plugins that were added before others have the first shot at
130 processing events. See
131 L<Object::Pluggable::Pipeline|Object::Pluggable::Pipeline> for details.
132  
133 my $pipeline = $ircd->pipeline();
134  
135 =head1 EVENTS
136  
137 =head2 SERVER hooks
138  
139 Hooks that are targeted toward data received from the server will get the
140 exact same arguments as if it was a normal event, look at the
141 POE::Component::Server::IRC::Backend docs for more information.
142  
143 B<Note:> Server methods are identified in the plugin namespace by the
144 subroutine prefix of IRCD_*. I.e. an ircd_cmd_kick event handler would be:
145  
146 sub IRCD_cmd_kick {}
147  
148 The only difference is instead of getting scalars, the hook will get a
149 reference to the scalar, to allow it to mangle the data. This allows the
150 plugin to modify data *before* they are sent out to registered sessions.
151  
152 They are required to return one of the exit codes so
153 POE::Component::Server::IRC::Backend will know what to do.
154  
155 Names of potential hooks:
156  
157 socketerr
158 connected
159 plugin_del
160 ...
161  
162 Keep in mind that they are always lowercased, check out the
163 POE::Component::Server::IRC documentation.
164  
165 =head2 C<_default>
166  
167 If a plugin doesn't have a specific hook method defined for an event, the
168 component will attempt to call a plugin's C<_default> method. The first
169 parameter after the plugin and irc objects will be the handler name.
170  
171 sub _default {
172 my ($self, $irc, $event) = splice @_, 0, 3;
173 return PCSI_EAT_NONE;
174 }
175  
176 The C<_default> handler is expected to return one of the exit codes so
177 POE::Component::Server::IRC::Backend will know what to do.
178  
179 =head1 EXPORTS
180  
181 The following constants are exported on demand.
182  
183 =head2 C<PCSI_EAT_NONE>
184  
185 This means the event will continue to be processed by remaining plugins and
186 finally, sent to interested sessions that registered for it.
187  
188 =head2 C<PCSI_EAT_CLIENT>
189  
190 This means the event will continue to be processed by remaining plugins but
191 it will not be sent to any sessions that registered for it.
192  
193 =head2 C<PCSI_EAT_PLUGIN>
194  
195 This means the event will not be processed by remaining plugins, it will go
196 straight to interested sessions.
197  
198 =head2 C<PCSI_EAT_ALL>
199  
200 This means the event will be completely discarded, no plugin or session
201 will see it.
202  
203 =head1 SEE ALSO
204  
205 L<Object::Pluggable|Object::Pluggable>
206  
207 =cut
« bin/pmkpasswd ↑ Summary