Fall back correctly between config methods
hook_user_config no falls back to global hook_config followed by file-based config followed by %defaults
This commit is contained in:
parent
5b8138971a
commit
18bfc45d0b
@ -145,25 +145,25 @@ sub config {
|
||||
|
||||
$self->log(LOGDEBUG, "in config($c)");
|
||||
|
||||
my $is_address = (ref $type and $type->can('address'));
|
||||
my @args = $is_address ? ('user_config',$type,$c) : ('config',$c);
|
||||
my ($rc, @config) = $self->run_hooks_no_respond(@args);
|
||||
return wantarray ? @config : $config[0] if $is_address;
|
||||
# first run the hooks
|
||||
my ($rc, @config);
|
||||
($rc, @config) = $self->run_hooks_no_respond('user_config',$type,$c)
|
||||
if ref $type and $type->can('address');
|
||||
return wantarray ? @config : $config[0]
|
||||
if defined $rc and $rc == OK;
|
||||
($rc, @config) = $self->run_hooks_no_respond('config',$c);
|
||||
$self->log(LOGDEBUG, "config($c): hook returned ($rc, @config) ");
|
||||
if ($rc == OK) {
|
||||
return wantarray ? @config : $config[0];
|
||||
}
|
||||
return wantarray ? @config : $config[0]
|
||||
if defined $rc and $rc == OK;
|
||||
|
||||
# and then get_qmail_config
|
||||
@config = $self->get_qmail_config($c, $type);
|
||||
if (@config) {
|
||||
return wantarray ? @config : $config[0];
|
||||
}
|
||||
return wantarray ? @config : $config[0]
|
||||
if @config;
|
||||
|
||||
# finally we use the default if there is any:
|
||||
if (exists($defaults{$c})) {
|
||||
return wantarray ? @config : $config[0];
|
||||
}
|
||||
return wantarray ? ($defaults{$c}) : $defaults{$c}
|
||||
if exists $defaults{$c};
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -18,7 +18,8 @@ sub __config {
|
||||
ok( $qp->command('HELO test') );
|
||||
ok( $qp->command('MAIL FROM:<test@example.com>') );
|
||||
my $sender = $qp->transaction->sender;
|
||||
$qp->hooks->{user_config} = [];
|
||||
$qp->hooks->{user_config} = undef;
|
||||
is( $qp->config('size_threshold'), 10000, 'use global config when user_config is absent' );
|
||||
is( $sender->config('test config'), undef, 'no user_config plugins exist' );
|
||||
$qp->hooks->{user_config} = [{ name => 'test hook', code => sub { return DECLINED } }];
|
||||
is( $sender->config('test config'), undef, 'no user_config plugins return OK' );
|
||||
|
Loading…
Reference in New Issue
Block a user