Skip to content

Commit

Permalink
Enabled plugin_debug effect Pipeline; Added send_event() method for i…
Browse files Browse the repository at this point in the history
…njecting events in the event handling system.
  • Loading branch information
bingos committed Oct 17, 2006
1 parent 21c4d4f commit fc975b6
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 6 deletions.
5 changes: 5 additions & 0 deletions Changes
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
Revision history for Perl extension POE::Component::IRC.

5.07 Tue Oct 17 11:37:28 BST 2006
- Enabled plugin_debug effect Pipeline.
- Added send_event() method for injecting events in the event
handling system.

5.06 Thu Oct 12 12:45:06 BST 2006
- Adjusted load() in PlugMan, suggested by Stefan Schwarzkopf.

Expand Down
21 changes: 15 additions & 6 deletions lib/POE/Component/IRC.pm
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ use vars qw($VERSION $REVISION $GOT_SSL $GOT_CLIENT_DNS);
# Load the plugin stuff
use POE::Component::IRC::Plugin qw( :ALL );

$VERSION = '5.06';
$VERSION = '5.07';
$REVISION = do {my@r=(q$Revision$=~/\d+/g);sprintf"%d"."%04d"x$#r,@r};

# BINGOS: I have bundled up all the stuff that needs changing for inherited classes
Expand Down Expand Up @@ -503,14 +503,18 @@ sub _parseline {
undef;
}

sub send_event {
my $self = shift;
$poe_kernel->call( $self->{SESSION_ID}, '__send_event', @_ );
return 1;
}

# Hack to make plugin_add/del send events from OUR session
sub __send_event {
my( $self, $event, @args ) = @_[ OBJECT, ARG0, ARG1 .. $#_ ];

# Actually send the event...
$self->_send_event( $event, @args );
return 1;
my( $self, $event, @args ) = @_[ OBJECT, ARG0, ARG1 .. $#_ ];
# Actually send the event...
$self->_send_event( $event, @args );
return 1;
}

# Sends an event to all interested sessions. This is a separate sub
Expand Down Expand Up @@ -2354,6 +2358,11 @@ created by the component.
Returns a reference to the L<POE::Component::IRC::Pipeline> object used by the plugin system.
=item send_event
Sends an event through the components event handling system. These will get processed by
plugins then by registered sessions. First argument is the event name, followed by any parameters for that event.
=back
=head1 INPUT
Expand Down
10 changes: 10 additions & 0 deletions lib/POE/Component/IRC/Pipeline.pm
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ sub new {
PIPELINE => [],
HANDLES => {},
IRC => $irc,
DEBUG => $irc->{plugin_debug},
}, $class;
}

Expand All @@ -26,6 +27,7 @@ sub push {
my $return;

eval { $return = $plug->PCI_register($self->{IRC}) };
warn "$@\n" if $@ and $self->{DEBUG};

if ($return) {
push @{ $self->{PIPELINE} }, $plug;
Expand All @@ -49,6 +51,7 @@ sub pop {
delete $self->{HANDLES}{$plug};

eval { $plug->PCI_unregister($self->{IRC}) };
warn "$@\n" if $@ and $self->{DEBUG};
$self->{IRC}->yield(__send_event => irc_plugin_del => $alias, $plug);

return wantarray() ? ($plug, $alias) : $plug;
Expand All @@ -63,6 +66,7 @@ sub unshift {
my $return;

eval { $return = $plug->PCI_register($self->{IRC}) };
warn "$@\n" if $@ and $self->{DEBUG};

if ($return) {
unshift @{ $self->{PIPELINE} }, $plug;
Expand All @@ -88,6 +92,7 @@ sub shift {
delete $self->{HANDLES}{$plug};

eval { $plug->PCI_unregister($self->{IRC}) };
warn "$@\n" if $@ and $self->{DEBUG};
$self->{IRC}->yield(__send_event => irc_plugin_del => $alias, $plug);

return wantarray() ? ($plug, $alias) : $plug;
Expand All @@ -107,6 +112,7 @@ sub replace {
delete $self->{PLUGS}{$old_a};
delete $self->{HANDLES}{$old_p};
eval { $old_p->PCI_unregister($self->{IRC}) };
warn "$@\n" if $@ and $self->{DEBUG};
$self->{IRC}->yield(__send_event => irc_plugin_del => $old_a, $old_p);

$@ = "Plugin named '$new_a' already exists ($self->{PLUGS}{$new_a}", return
Expand All @@ -115,6 +121,7 @@ sub replace {
my $return;

eval { $return = $new_p->PCI_register($self->{IRC}) };
warn "$@\n" if $@ and $self->{DEBUG};

if ($return) {
$self->{PLUGS}{$new_p} = $new_a;
Expand Down Expand Up @@ -152,6 +159,7 @@ sub remove {
}

eval { $old_p->PCI_unregister($self->{IRC}) };
warn "$@\n" if $@ and $self->{DEBUG};
$self->{IRC}->yield(__send_event => irc_plugin_del => $old_a, $old_p);

return wantarray ? ($old_p, $old_a) : $old_p;
Expand Down Expand Up @@ -203,6 +211,7 @@ sub insert_before {
my $return;

eval { $return = $new_p->PCI_register($self->{IRC}) };
warn "$@\n" if $@ and $self->{DEBUG};

if ($return) {
$self->{PLUGS}{$new_p} = $new_a;
Expand Down Expand Up @@ -237,6 +246,7 @@ sub insert_after {
my $return;

eval { $return = $new_p->PCI_register($self->{IRC}) };
warn "$@\n" if $@ and $self->{DEBUG};

if ($return) {
$self->{PLUGS}{$new_p} = $new_a;
Expand Down

0 comments on commit fc975b6

Please sign in to comment.