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:
parent
8c32a22d27
commit
0e5b4e63ec
@ -241,13 +241,18 @@ sub run_hooks {
|
|||||||
|
|
||||||
sub _register_hook {
|
sub _register_hook {
|
||||||
my $self = shift;
|
my $self = shift;
|
||||||
my ($hook, $code) = @_;
|
my ($hook, $code, $unshift) = @_;
|
||||||
|
|
||||||
#my $plugin = shift; # see comment in Plugin.pm:register_hook
|
#my $plugin = shift; # see comment in Plugin.pm:register_hook
|
||||||
|
|
||||||
$self->{_hooks} = $Qpsmtpd::_hooks;
|
$self->{_hooks} = $Qpsmtpd::_hooks;
|
||||||
my $hooks = $self->{_hooks};
|
my $hooks = $self->{_hooks};
|
||||||
push @{$hooks->{$hook}}, $code;
|
if ($unshift) {
|
||||||
|
unshift @{$hooks->{$hook}}, $code;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
push @{$hooks->{$hook}}, $code;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
1;
|
1;
|
||||||
|
@ -14,15 +14,16 @@ sub new {
|
|||||||
}
|
}
|
||||||
|
|
||||||
sub register_hook {
|
sub register_hook {
|
||||||
my ($plugin, $hook, $method) = @_;
|
my ($plugin, $hook, $method, $unshift) = @_;
|
||||||
|
|
||||||
die $plugin->plugin_name . " : Invalid hook: $hook" unless $hooks{$hook};
|
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
|
# 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.
|
# we should pass the plugin object and method name ... hmn.
|
||||||
$plugin->qp->_register_hook($hook, { code => sub { local $plugin->{_qp} = shift; $plugin->$method(@_) },
|
$plugin->qp->_register_hook($hook, { code => sub { local $plugin->{_qp} = shift; $plugin->$method(@_) },
|
||||||
name => $plugin->plugin_name
|
name => $plugin->plugin_name,
|
||||||
}
|
},
|
||||||
|
$unshift,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user