From 03b8cda2b568ec1ef78349a73a827e95546d888b Mon Sep 17 00:00:00 2001 From: Matt Sergeant Date: Sun, 2 Nov 2003 11:13:08 +0000 Subject: [PATCH] Don't keep the _qp around - just pass it in to each hook. git-svn-id: https://svn.perl.org/qpsmtpd/trunk@179 958fd67b-6ff1-0310-b445-bb7760255be9 --- lib/Qpsmtpd.pm | 9 ++++----- lib/Qpsmtpd/Plugin.pm | 3 ++- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/lib/Qpsmtpd.pm b/lib/Qpsmtpd.pm index 7e1b6d3..85d989b 100644 --- a/lib/Qpsmtpd.pm +++ b/lib/Qpsmtpd.pm @@ -2,7 +2,7 @@ package Qpsmtpd; use strict; $Qpsmtpd::VERSION = "0.27-dev"; -sub TRACE_LEVEL { 6 } +sub TRACE_LEVEL () { 6 } use Sys::Hostname; use Qpsmtpd::Constants; @@ -88,7 +88,6 @@ sub get_qmail_config { } - sub load_plugins { my $self = shift; my @plugins = $self->config('plugins'); @@ -100,7 +99,7 @@ sub load_plugins { for my $plugin (@plugins) { $self->log(7, "Loading $plugin"); ($plugin, my @args) = split /\s+/, $plugin; - + my $plugin_name = $plugin; # Escape everything into valid perl identifiers @@ -116,7 +115,7 @@ sub load_plugins { # don't reload plugins if they are already loaded next if defined &{"Qpsmtpd::Plugin::${plugin_name}::register"}; - + my $sub; open F, "$dir/$plugin" or die "could not open $dir/$plugin: $!"; { @@ -163,7 +162,7 @@ sub run_hooks { my @r; for my $code (@{$self->{_hooks}->{$hook}}) { $self->log(5, "running plugin ", $code->{name}); - eval { (@r) = &{$code->{code}}($self->can('transaction') ? $self->transaction : {}, @_); }; + eval { (@r) = $code->{code}->($self, $self->can('transaction') ? $self->transaction : {}, @_); }; $@ and $self->log(0, "FATAL PLUGIN ERROR: ", $@) and next; !defined $r[0] and $self->log(1, "plugin ".$code->{name} diff --git a/lib/Qpsmtpd/Plugin.pm b/lib/Qpsmtpd/Plugin.pm index b869e12..48696e1 100644 --- a/lib/Qpsmtpd/Plugin.pm +++ b/lib/Qpsmtpd/Plugin.pm @@ -12,10 +12,11 @@ sub register_hook { my ($plugin, $hook, $method) = @_; # 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 { $plugin->$method(@_) }, + $plugin->qp->_register_hook($hook, { code => sub { local $plugin->{_qp} = shift; $plugin->$method(@_) }, name => $plugin->plugin_name } ); + delete $plugin->{_qp}; } sub qp {