From: Chris Nehren Date: Sun, 4 Sep 2011 05:59:27 +0000 (-0400) Subject: fix transport support in the dispatcher so it can be overridden at runtime X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=018a0a651c567c58ec56701b11d2741bfe640822;p=p5sagit%2FPromulger.git fix transport support in the dispatcher so it can be overridden at runtime --- diff --git a/lib/Promulger/Dispatch.pm b/lib/Promulger/Dispatch.pm index 2892cff..b7fc749 100644 --- a/lib/Promulger/Dispatch.pm +++ b/lib/Promulger/Dispatch.pm @@ -2,6 +2,7 @@ package Promulger::Dispatch; use Moo; use Method::Signatures::Simple; use autodie ':all'; +use Scalar::Util 'blessed'; use Email::Address; use Email::MIME; @@ -21,7 +22,17 @@ has transport => ( or die "transport must do Email::Sender::Transport role"; }, default => sub { - Email::Sender::Transport::Sendmail->new + my $config = Promulger::Config->config; + my $class; + if($class = $config->{mailer}) { + if($class !~ /::/) { + $class = "Email::Sender::Transport::${class}"; + } + } else { + $class = 'Email::Sender::Transport::Sendmail'; + } + Class::MOP::load_class($class); + $class->new; }, ); @@ -95,17 +106,6 @@ method post_message ($list, $email, $config) { } method send_message ($message) { - my $config = Promulger::Config->config; - my ($class, $transport); - if($class = $config->{mailer}) { - if($class !~ /::/) { - $class = "Email::Sender::Transport::${class}"; - } - } else { - $class = 'Email::Sender::Transport::Sendmail'; - } - Class::MOP::load_class($class); - $transport = $class->new; Email::Sender::Simple::sendmail( $message, {