I have a module that uses to Mail::Mailer to send out emails. Now I could really do with a test script to lock its fairly basic functionality in place. I don't want to change the code of this module at the moment as it is in use in production. I just want to build a test script around it.

I have tried using Test::MockObject and this works as far as it goes. So I can see that in my test script I can set up my mockup of Mail::Mailer in a BEGIN function. Then when I load the module under test and debug it - lo and behold the created $mailer object is a Test::MockObject rather than a Mail::Mailer. I can mock the open and close methods. The issue is that the code calls

print {$mailer} $body || croak "couldn't send whole message: $!\n";
so $mailer needs to be a GLOB reference. Fine I can pass a GLOB reference into the Test::MockObject constructor and yes the mock object is at root a GLOB reference. But I am still a lost. It is as if I have opened up a telephone exchange box and I know more or less how the cabling works, but I have lost the colour coding of the cables. Could anyone advise me how you actually connect the print cable up with the glob cable?


In reply to How to mock Mail::Mailer by SilasTheMonk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.