plugin wrapping:
replace wrap_plugin implementation with isa_plugin inheritance based implementation git-svn-id: https://svn.perl.org/qpsmtpd/trunk@312 958fd67b-6ff1-0310-b445-bb7760255be9
This commit is contained in:
parent
fb3f0b4604
commit
0b16ec9418
@ -52,37 +52,26 @@ sub connection {
|
|||||||
shift->qp->connection;
|
shift->qp->connection;
|
||||||
}
|
}
|
||||||
|
|
||||||
sub wrap_plugin {
|
# plugin inheritance:
|
||||||
my ($self, $plugin_file, @args) = @_;
|
# usage:
|
||||||
|
# sub register {
|
||||||
|
# my $self = shift;
|
||||||
|
# $self->isa_plugin("rhsbl");
|
||||||
|
# $self->SUPER::register(@_);
|
||||||
|
# }
|
||||||
|
sub isa_plugin {
|
||||||
|
my ($self, $parent) = @_;
|
||||||
|
my ($currentPackage) = caller;
|
||||||
|
my $newPackage = $currentPackage."::_isa_";
|
||||||
|
|
||||||
# Wrap all of the methods in an existing plugin so that functions
|
return if defined &{"${newPackage}::register"};
|
||||||
# can easily be replaced. Yes, we could use something like
|
|
||||||
# Hook::Lexwrap isntead, but since it's only 15 lines of code, might
|
|
||||||
# as well do it ourself.
|
|
||||||
|
|
||||||
# Static methods in plugins will probably not work right in this
|
Qpsmtpd::_compile($self->plugin_name . "_isa",
|
||||||
# scheme.
|
$newPackage,
|
||||||
|
"plugins/$parent"); # assumes Cwd is qpsmtpd root
|
||||||
# Load the new plugin under our namespace.
|
|
||||||
my $newPackage = __PACKAGE__."::_wrap_";
|
|
||||||
Qpsmtpd::_compile($self->plugin_name, $newPackage, $plugin_file)
|
|
||||||
unless defined &{"${newPackage}::register"};
|
|
||||||
|
|
||||||
no strict 'refs';
|
no strict 'refs';
|
||||||
my $currentPackage = ref $self;
|
push @{"${currentPackage}::ISA"}, $newPackage;
|
||||||
local *{${newPackage}."::register_hook"} = sub {
|
|
||||||
if (defined &{ $currentPackage . "::$_[2]"}) {
|
|
||||||
# We're wrapping this hook. Store the old value in $self-{_wrap_FUNC}
|
|
||||||
$self->{"_wrap_".$_[2]} = \&{${newPackage}."::$_[2]"};
|
|
||||||
} else {
|
|
||||||
# We're not wrapping this hook. Alias it into our namespace.
|
|
||||||
*{$currentPackage."::$_[2]"} = \&{${newPackage}."::$_[2]"};
|
|
||||||
}
|
|
||||||
$self->register_hook($_[1],$_[2]);
|
|
||||||
};
|
|
||||||
|
|
||||||
$self->{_wrapped_package} = $newPackage;
|
|
||||||
$newPackage->register($self->{_qp},@args);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
1;
|
1;
|
||||||
|
Loading…
Reference in New Issue
Block a user