Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

Re^3: Return value of a sub

by Joost (Canon)
on Jul 07, 2009 at 19:31 UTC ( [id://777983]=note: print w/replies, xml ) Need Help??


in reply to Re^2: Return value of a sub
in thread Return value of a sub

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.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://777983]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others cooling their heels in the Monastery: (3)
As of 2024-04-26 00:05 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found