Fix for hooks not running with previous patch, caused by qpsmtpd objects not

asking each plugin to register. There is slightly more overhead this way,
but it feels more correct, and we can fix the overhead later in a more clean
way.


git-svn-id: https://svn.perl.org/qpsmtpd/trunk@300 958fd67b-6ff1-0310-b445-bb7760255be9
This commit is contained in:
Matt Sergeant 2004-09-05 16:28:08 +00:00
parent 325bb77713
commit 606519b06c
2 changed files with 38 additions and 32 deletions

View File

@ -111,6 +111,40 @@ sub _config_from_file {
return wantarray ? @config : $config[0];
}
sub _compile {
my ($plugin, $package, $file) = @_;
my $sub;
open F, $file or die "could not open $file: $!";
{
local $/ = undef;
$sub = <F>;
}
close F;
my $line = "\n#line 1 $file\n";
my $eval = join(
"\n",
"package $package;",
'use Qpsmtpd::Constants;',
"require Qpsmtpd::Plugin;",
'use vars qw(@ISA);',
'@ISA = qw(Qpsmtpd::Plugin);',
"sub plugin_name { qq[$plugin] }",
$line,
$sub,
"\n", # last line comment without newline?
);
#warn "eval: $eval";
$eval =~ m/(.*)/s;
$eval = $1;
eval $eval;
die "eval $@" if $@;
}
sub load_plugins {
my $self = shift;
@ -174,38 +208,8 @@ sub _load_plugins {
my $package = "Qpsmtpd::Plugin::$plugin_name";
# don't reload plugins if they are already loaded
next if defined &{"${package}::register"};
my $sub;
open F, "$dir/$plugin" or die "could not open $dir/$plugin: $!";
{
local $/ = undef;
$sub = <F>;
}
close F;
my $line = "\n#line 1 $dir/$plugin\n";
my $eval = join(
"\n",
"package $package;",
'use Qpsmtpd::Constants;',
"require Qpsmtpd::Plugin;",
'use vars qw(@ISA);',
'@ISA = qw(Qpsmtpd::Plugin);',
"sub plugin_name { qq[$plugin_name] }",
$line,
$sub,
"\n", # last line comment without newline?
);
#warn "eval: $eval";
$eval =~ m/(.*)/s;
$eval = $1;
eval $eval;
die "eval $@" if $@;
_compile($plugin_name, $package, "$dir/$plugin") unless
defined &{"${package}::register"};
my $plug = $package->new();
$plug->_register($self, @args);

View File

@ -34,6 +34,8 @@ sub new {
# this list of valid commands should probably be a method or a set of methods
$self->{_commands} = \%commands;
$self->load_plugins;
$self;
}