Ok, I lied a little. The full code for the sub is:
sub sendMessage {
my (%params) = @_;
return if ! CheckParams (\%params, \@okMsgParams, \@requiredMsgPar
+ams);
$params{Type} = 'text/plain' if ! exists $params{Type};
$params{Date} = Date::EzDate->new ()->{'%Y:%m:%d %T'}
if ! exists $params{date};
$params{From} = $BuildManagerContext::gMyEmailAddress if ! exists
+$params{From};
my $msg = MIME::Lite->new (%params);
my $result = eval {$msg->send};
if (! defined $result) {
my $mailMsg = "Error: failed to send message below. Error is $
+@\n";
$mailMsg .= "The following parameters were supplied:\n";
$mailMsg .= "$_: $params{$_}\n" for keys %params;
$mailMsg ||= '-- No parameters supplied --';
BuildManagerContext::AddLogString ($mailMsg, 1);
BuildManagerContext::FlushLogStrings ();
return undef;
}
return 1;
}
and it gets called from many different places. However it is where all the parts come together and as suggested in the OP it is really only the two lines of the send that are important to the problem. tye's solution gives me exactly the tool that is needed and I can use the same technique in other places to similar effect.
DWIM is Perl's answer to Gödel
|