moved config() from Qpsmtpd -> Q::Config.pm

This commit is contained in:
Matt Simerson 2014-09-16 09:26:55 -07:00
parent d83268e448
commit b0c3d715cc
2 changed files with 36 additions and 31 deletions

View File

@ -130,37 +130,9 @@ sub conf {
} }
sub config { sub config {
my ($self, $c, $type) = @_; my $self = shift;
return $self->conf->config($self, @_);
$self->log(LOGDEBUG, "in config($c)"); };
# first run the user_config hooks
my ($rc, @config);
if (ref $type && $type->can('address')) {
($rc, @config) = $self->run_hooks_no_respond('user_config', $type, $c);
if (defined $rc && $rc == OK) {
return wantarray ? @config : $config[0];
};
};
# then run the config hooks
($rc, @config) = $self->run_hooks_no_respond('config', $c);
$self->log(LOGDEBUG,
"config($c): hook returned ("
. join(',', map { defined $_ ? $_ : 'undef' } ($rc, @config))
. ")"
);
if (defined $rc && $rc == OK) {
return wantarray ? @config : $config[0];
};
# then qmail
@config = $self->conf->get_qmail($c, $type);
return wantarray ? @config : $config[0] if @config;
# then the default, which may be undefined
return $self->conf->default($c);
}
sub config_dir { sub config_dir {
my $self = shift; my $self = shift;

View File

@ -27,6 +27,39 @@ sub log {
warn join(' ', $$, @log) . "\n"; warn join(' ', $$, @log) . "\n";
} }
sub config {
my ($self, $qp, $c, $type) = @_;
$qp->log(LOGDEBUG, "in config($c)");
# first run the user_config hooks
my ($rc, @config);
if (ref $type && $type->can('address')) {
($rc, @config) = $qp->run_hooks_no_respond('user_config', $type, $c);
if (defined $rc && $rc == OK) {
return wantarray ? @config : $config[0];
};
};
# then run the config hooks
($rc, @config) = $qp->run_hooks_no_respond('config', $c);
$qp->log(LOGDEBUG,
"config($c): hook returned ("
. join(',', map { defined $_ ? $_ : 'undef' } ($rc, @config))
. ")"
);
if (defined $rc && $rc == OK) {
return wantarray ? @config : $config[0];
};
# then qmail
@config = $self->get_qmail($c, $type);
return wantarray ? @config : $config[0] if @config;
# then the default, which may be undefined
return $self->default($c);
}
sub config_dir { sub config_dir {
my ($self, $config) = @_; my ($self, $config) = @_;
if (exists $dir_memo{$config}) { if (exists $dir_memo{$config}) {