in reply to Checking parameters passed to a third party module during testing

I would probably factor out the code that populates %params. That would accomplish to good things. It would remove some clutter from the routine doing the sending and it would make it dead simple to test the refactored code.

Phil

  • Comment on Re: Checking parameters passed to a third party module during testing

Replies are listed 'Best First'.
Re^2: Checking parameters passed to a third party module during testing
by GrandFather (Saint) on Oct 18, 2006 at 20:09 UTC

    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