From 0e5b4e63ecbd9b3cd028041ec15c62d5d5b81d78 Mon Sep 17 00:00:00 2001 From: Matt Sergeant Date: Fri, 11 Jun 2004 20:01:17 +0000 Subject: [PATCH] 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 --- lib/Qpsmtpd.pm | 9 +++++++-- lib/Qpsmtpd/Plugin.pm | 7 ++++--- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/lib/Qpsmtpd.pm b/lib/Qpsmtpd.pm index b111a6a..6a6598c 100644 --- a/lib/Qpsmtpd.pm +++ b/lib/Qpsmtpd.pm @@ -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; diff --git a/lib/Qpsmtpd/Plugin.pm b/lib/Qpsmtpd/Plugin.pm index e2a0fbe..63da30b 100644 --- a/lib/Qpsmtpd/Plugin.pm +++ b/lib/Qpsmtpd/Plugin.pm @@ -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, ); }