| 1 |
NAME |
| 2 |
PerlX::Assert - yet another assertion keyword |
| 3 |
|
| 4 |
SYNOPSIS |
| 5 |
use PerlX::Assert; |
| 6 |
|
| 7 |
assert { 1 >= 10 }; |
| 8 |
|
| 9 |
DESCRIPTION |
| 10 |
PerlX::Assert is a framework for embedding assertions in Perl code. Under |
| 11 |
normal circumstances, assertions are not checked; they are optimized away |
| 12 |
at compile time. |
| 13 |
|
| 14 |
However if, at compile time, any of the following environment variables is |
| 15 |
true, assertions are checked, and if they fail, throw an exception. |
| 16 |
|
| 17 |
* `PERL_STRICT` |
| 18 |
|
| 19 |
* `AUTHOR_TESTING` |
| 20 |
|
| 21 |
* `EXTENDED_TESTING` |
| 22 |
|
| 23 |
* `RELEASE_TESTING` |
| 24 |
|
| 25 |
That is, assertions will only typically be checked when the test suite is |
| 26 |
being run on the authors' machine, or otherwise opted into. |
| 27 |
|
| 28 |
The exact decision logic can be found in Devel::StrictMode. |
| 29 |
|
| 30 |
You can also force assertions to be checked using: |
| 31 |
|
| 32 |
use PerlX::Assert -check; |
| 33 |
|
| 34 |
There are four syntaxes for expressing assertions: |
| 35 |
|
| 36 |
assert EXPR; |
| 37 |
assert { BLOCK }; |
| 38 |
assert "name", EXPR; |
| 39 |
assert "name" { BLOCK }; |
| 40 |
|
| 41 |
Assertions can be named, which is probably a good idea because this module |
| 42 |
(and the rest of Moops) screws up Perl's reporting of line numbers. Names |
| 43 |
must be a quoted string (single or double quotes, or the `q` or `qq` |
| 44 |
quote-like operators); general expressions are not supported because |
| 45 |
Text::Balanced is used to parse the assertion name. An assertion is a |
| 46 |
statement, so must be followed by a semicolon unless it's the last |
| 47 |
statement in a block. |
| 48 |
|
| 49 |
PerlX::Assert was originally distributed as part of Moops, but was fairly |
| 50 |
independent of the rest of it, and has been spun off as a separate |
| 51 |
release, and backported to Perl 5.8.1. |
| 52 |
|
| 53 |
Assertions that span multiple lines are very likely to cause problems on |
| 54 |
versions of Perl prior to 5.12. If the `assert` keyword, the entire name, |
| 55 |
and the start of the expression or block are all on the same line, this |
| 56 |
should be sufficient. |
| 57 |
|
| 58 |
BUGS |
| 59 |
Please report any bugs to |
| 60 |
<http://rt.cpan.org/Dist/Display.html?Queue=PerlX-Assert>. |
| 61 |
|
| 62 |
SEE ALSO |
| 63 |
Devel::Assert, Carp::Assert. |
| 64 |
|
| 65 |
AUTHOR |
| 66 |
Toby Inkster <[email protected]>. |
| 67 |
|
| 68 |
COPYRIGHT AND LICENCE |
| 69 |
This software is copyright (c) 2013-2014 by Toby Inkster. |
| 70 |
|
| 71 |
This is free software; you can redistribute it and/or modify it under the |
| 72 |
same terms as the Perl 5 programming language system itself. |
| 73 |
|
| 74 |
DISCLAIMER OF WARRANTIES |
| 75 |
THIS PACKAGE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR IMPLIED |
| 76 |
WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF |
| 77 |
MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. |
| 78 |
|