Skip to content

Commit

Permalink
Make it possible to change the event name when using a hook_print filter
Browse files Browse the repository at this point in the history
git-svn-id: https://xchat.svn.sourceforge.net/svnroot/xchat@1491 893a96be-7f27-4fdf-9d1e-6aeec9d3cce1
  • Loading branch information
lsitu committed Feb 24, 2011
1 parent b5e1bb3 commit bb03591
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions plugins/perl/lib/Xchat.pm
Original file line number Diff line number Diff line change
Expand Up @@ -212,19 +212,26 @@ sub hook_print {
my $cb = $callback;
$callback = sub {
my @args = @{$_[0]};
my $event_data = $_[1];
my $event_name = $event;
my $last_arg = @args - 1;

my @new = $cb->( \@args, $_[1], $event );
my @new = $cb->( \@args, $event_data, $event_name );

# allow changing event by returning the new value
if( @new > @args ) {
$event_name = pop @new;
}

# a filter can either return the new results or it can modify
# @_ in place.
if( @new ) {
emit_print( $event, @new[ 0 .. $last_arg ] );
if( @new == @args ) {
emit_print( $event_name, @new[ 0 .. $last_arg ] );
return EAT_ALL;
} elsif(
join( "\0", @{$_[0]} ) ne join( "\0", @args[ 0 .. $last_arg ] )
) {
emit_print( $event, @args[ 0 .. $last_arg ] );
emit_print( $event_name, @args[ 0 .. $last_arg ] );
return EAT_ALL;
}

Expand Down

0 comments on commit bb03591

Please sign in to comment.