in reply to Re^2: Testing error handling that calls "die"
in thread Testing error handling that calls "die"

One other thing surprised me slightly. Every use of ok I had seen previously uses brackets, but I notice that your examples do not. I have put brackets in for consistency, but is this just cargo cult? If not, what is the effect of using the brackets?

The parenthesis after a subroutine name are another peculiarity of Perl 5 :-)

When perl enounters an identifier like ok in the source code, it can interpret it in two ways: either as a "barword" (a string literal), or as the name of a subroutine.

If perl knows about a subroutine of that name, it decides in favor of the subroutine interpretation, otherwise it chooses the bareword. If you put parenthesis after the identifier, it always chooses the subroutine.

So, the parens are only needed if the subroutine is declared later in the file. Since you use Test::More; (or something similar) at the start of your test file, all the testing routines are immediately imported, and thus known as subroutines.

Here are a few examples of the parsing differences:

$ perl -le 'print STDOUT foo' # bareword foo $ perl -le 'use strict; print STDOUT foo' # strict disables barewords Bareword "foo" not allowed while "strict subs" in use at -e line 1. Execution of -e aborted due to compilation errors. $ perl -e 'use strict; sub foo { }; foo' # works fine $ perl -e 'use strict; foo; sub foo { };' # error, foo is a bareword, +because it's not declared yet Bareword "foo" not allowed while "strict subs" in use at -e line 1. Execution of -e aborted due to compilation errors. $ perl -e 'use strict; foo(); sub foo { };' # that's where you actuall +y need the parens; no error