Add unshift parameter to register_hook, allowing you to put the hook at the

start of the queue


git-svn-id: https://svn.perl.org/qpsmtpd/trunk@244 958fd67b-6ff1-0310-b445-bb7760255be9
This commit is contained in:
Matt Sergeant 2004-06-11 20:01:17 +00:00
parent 8c32a22d27
commit 0e5b4e63ec
2 changed files with 11 additions and 5 deletions

View File

@ -241,13 +241,18 @@ sub run_hooks {
sub _register_hook {
my $self = shift;
my ($hook, $code) = @_;
my ($hook, $code, $unshift) = @_;
#my $plugin = shift; # see comment in Plugin.pm:register_hook
$self->{_hooks} = $Qpsmtpd::_hooks;
my $hooks = $self->{_hooks};
push @{$hooks->{$hook}}, $code;
if ($unshift) {
unshift @{$hooks->{$hook}}, $code;
}
else {
push @{$hooks->{$hook}}, $code;
}
}
1;

View File

@ -14,15 +14,16 @@ sub new {
}
sub register_hook {
my ($plugin, $hook, $method) = @_;
my ($plugin, $hook, $method, $unshift) = @_;
die $plugin->plugin_name . " : Invalid hook: $hook" unless $hooks{$hook};
# I can't quite decide if it's better to parse this code ref or if
# we should pass the plugin object and method name ... hmn.
$plugin->qp->_register_hook($hook, { code => sub { local $plugin->{_qp} = shift; $plugin->$method(@_) },
name => $plugin->plugin_name
}
name => $plugin->plugin_name,
},
$unshift,
);
}