From b0c3d715cc2ab7ef9f8216cf72388af07a82e3f3 Mon Sep 17 00:00:00 2001 From: Matt Simerson Date: Tue, 16 Sep 2014 09:26:55 -0700 Subject: [PATCH] moved config() from Qpsmtpd -> Q::Config.pm --- lib/Qpsmtpd.pm | 34 +++------------------------------- lib/Qpsmtpd/Config.pm | 33 +++++++++++++++++++++++++++++++++ 2 files changed, 36 insertions(+), 31 deletions(-) diff --git a/lib/Qpsmtpd.pm b/lib/Qpsmtpd.pm index 612b87a..c563a04 100644 --- a/lib/Qpsmtpd.pm +++ b/lib/Qpsmtpd.pm @@ -130,37 +130,9 @@ sub conf { } sub config { - my ($self, $c, $type) = @_; - - $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); -} + my $self = shift; + return $self->conf->config($self, @_); +}; sub config_dir { my $self = shift; diff --git a/lib/Qpsmtpd/Config.pm b/lib/Qpsmtpd/Config.pm index 021315c..ac1c6a7 100644 --- a/lib/Qpsmtpd/Config.pm +++ b/lib/Qpsmtpd/Config.pm @@ -27,6 +27,39 @@ sub log { 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 { my ($self, $config) = @_; if (exists $dir_memo{$config}) {