PerlX::Assert - yet another assertion keyword
use PerlX::Assert; assert { 1 >= 10 };
PerlX::Assert is a framework for embedding assertions in Perl code. Under normal circumstances, assertions are not checked; they are optimized away at compile time.
However if, at compile time, any of the following environment variables is true, assertions are checked, and if they fail, throw an exception.
AUTHOR_TESTING
AUTOMATED_TESTING
EXTENDED_TESTING
RELEASE_TESTING
That is, assertions will only typically be checked when the test suite is being run on the authors' machine, or being run by CPAN smoke testers.
You can also force assertions to be checked using:
use PerlX::Assert -check;
Or if using Moops, use the ':assertions' trait to force assertion checking:
class Whiner :assertions { # ... }
There are four syntaxes for expressing assertions:
assert EXPR; assert { BLOCK }; assert "name", EXPR; assert "name" { BLOCK };
Assertions can be named, which is probably a good idea because this module (and the rest of Moops) screws up Perl's reporting of line numbers. Names must be a quoted string. (Single or double quotes, or the q or qq quote-like operators.) An assertion is a statement, so must be followed by a semicolon, unless it's the last statement in a block.
q
qq
PerlX::Assert is currently distributed as part of Moops, but is fairly independent of the rest of it, and may be spun off as a separate release in the future.
Please report any bugs to http://rt.cpan.org/Dist/Display.html?Queue=Moops.
Devel::Assert, Carp::Assert.
Moops.
Toby Inkster <tobyink@cpan.org>.
This software is copyright (c) 2013 by Toby Inkster.
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.
THIS PACKAGE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
To install Moops, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Moops
CPAN shell
perl -MCPAN -e shell install Moops
For more information on module installation, please visit the detailed CPAN module installation guide.