I think my confusion arose from the fact that the lives_ok test of Test::Exception also accepts these type of test constructs.
Now that that's cleared up, you might be interested why Test::Exception requires subroutine references: it wouldn't be possible to catch the exception thrown otherwise (well, actually you could hack around that, but it wouldn't be as reliable and it would probably mess up the code flow). Inside the Test::Exception code there's probably something like eval { $coderef->() } # now do something with $@.

All of the Test::Exception test functions also allow you to leave off the "sub", and instead just use curly braces, but that's really just a convenience made possible by the often misunderstood prototype facility; you're still passing a subroutine reference as the first argument.


In reply to Re^3: Return value of a sub by Joost
in thread Return value of a sub by elTriberium

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.