Advertisement
teknogeek

All plugin subroutines

May 12th, 2013
181
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Perl 6 1.49 KB | None | 0 0
  1. # this gets called when the plugin is loaded
  2. sub start {
  3.     my ($kernel, $heap) = @_[KERNEL, HEAP];
  4.     $kernel->alias_set(PLUGIN_NAME);
  5. }
  6.  
  7. # this gets called when the plugin is unloaded
  8. sub stop {
  9.     my ($kernel, $heap) = @_[KERNEL, HEAP];
  10. }
  11.  
  12. # got a request
  13. sub got_request {
  14.     my ($kernel, $heap, $user, $location, $replyto, $extra, $keyword, $message) = @_[KERNEL, HEAP, ARG0, ARG1, ARG2, ARG3, ARG4, ARG5];
  15.     # reply($kernel, $replyto, $extra, "message here");
  16. }
  17.  
  18. # got a notice
  19. sub got_notice {
  20.     my ($kernel, $heap, $target, $extra, $keyword, $message) = @_[KERNEL, HEAP, ARG0, ARG1, ARG2, ARG3];
  21. }
  22.  
  23. # got a reply to a request
  24. sub got_reply {
  25.     my ($kernel, $heap, $extra, $keyword, $message) = @_[KERNEL, HEAP, ARG0, ARG1, ARG2];
  26. }
  27.  
  28.  
  29. # don't touch anything beyond this point unless you know what you're doing
  30.  
  31. # load plugin
  32. sub load {
  33.     my (undef, $config) = @_;
  34.     my $session = POE::Session->create(
  35.         inline_states => {
  36.             _start => \&start,
  37.             stop => \&stop,
  38.             unload => \&unload,
  39.             got_notice => \&got_notice,
  40.             got_request => \&got_request,
  41.             got_reply => \&got_reply,
  42.         },
  43.         heap => { name => PLUGIN_NAME },
  44.     );
  45.     register_notice_keywords(PLUGIN_NAME, lc(PLUGIN_NAME), NOTICE_KEYWORDS);
  46.     register_request_keywords(PLUGIN_NAME, REQUEST_KEYWORDS);
  47.     register_reply_keywords(PLUGIN_NAME, lc(PLUGIN_NAME), REPLY_KEYWORDS);
  48. }
  49.  
  50. # unload plugin
  51. sub unload {
  52.     my ($kernel, $heap, $session) = @_[KERNEL, HEAP, SESSION];
  53.     $kernel->call($session, 'stop');
  54.     $kernel->alias_remove(PLUGIN_NAME);
  55.     $kernel->signal($session, 'KILL');
  56. }
  57.  
  58. #1;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement