in reply to POE::Component::IRC::Plugin Run a CMD All 5mins
PoCo-IRC plugins effectively are executed within the component's POE session
This means that if you want to make use of POE::Kernel's alarms/delays you have a number of different approaches:
- You can setup your own POE session within your plugin. There is an example of this in the POE cookbook, then setup up your delays/alarms.
- Alternatively, you can get creative and register an object state handler from your plugin with the PoCo-IRC session:
package PluginDelay; use strict; use warnings; use POE; # import POE stuff use POE::Component::IRC::Plugin qw( :ALL ); # Plugin object constructor sub new { my ($package) = shift; return bless {}, $package; } sub PCI_register { my ( $self, $irc ) = splice @_, 0, 2; $irc->plugin_register( $self, 'SERVER', qw(public) ); # Register an object state handler # Try not to use something poco-irc already uses # using the name of your plugin is a good practise $poe_kernel->state( 'PluginDelay_alarm', $self ); # Set our initial alarm $kernel->delay( 'PluginDelay_alarm', 5 * 60 ); return 1; } # This is method is mandatory but we don't actually have anything to d +o. sub PCI_unregister { return 1; } sub PluginDelay_alarm { my ($kernel,$self,$irc) = @_[KERNEL,OBJECT,HEAP]; # Do something funky. # Set the next alarm up $kernel->delay( 'PluginDelay_alarm', 5 * 60 ); return; } 1;
In Section
Seekers of Perl Wisdom