PerlX::Assert(3pm)
π PerlX::Assert π
okay bestie, welcome to PerlX::Assert(3pm) β it lives in the User Contributed Perl Documentation section of your man pages, and it is literally yet another assertion keyword. iconic behavior, honestly. β¨
π¦ NAME π¦
PerlX::Assert β yet another assertion keyword π
πΈ SYNOPSIS πΈ
use PerlX::Assert;
assert { 1 >= 10 };
that's it. that's the whole vibe. π«Ά
β¨ DESCRIPTION β¨
PerlX::Assert is a whole framework for embedding assertions in Perl code, and here's the gag: under normal circumstances, assertions are not checked at all β they get optimized away at compile time. poof. gone. not me being invisible at the function call π
But!! if, at compile time, any of the following environment variables is true, then the assertions are checked, and if they fail, they throw an exception:
PERL_STRICTAUTHOR_TESTINGEXTENDED_TESTINGRELEASE_TESTING
so basically, assertions only typically get checked when the test suite is being run on the authors' machine, or when somebody otherwise opts into it. main character testing energy only. π
the exact decision logic lives over in Devel::StrictMode if you wanna go read the receipts. π
you can also force assertions to be checked, like this:
use PerlX::Assert -check;
and there are four syntaxes for expressing assertions, bestie:
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 π so the name is your bestie when you're trying to figure out which assertion ghosted you.
Names must be a quoted string β single quotes, double quotes, or the q or qq quote-like operators. General expressions are not supported, because Text::Balanced is what gets used to parse the assertion name. so don't try to get cute with it. π
also!! an assertion is a statement, so it must be followed by a semicolon β unless it's the very last statement in a block. periodt.
PerlX::Assert was originally distributed as part of Moops, but it was fairly independent of the rest of it, so it got spun off as a separate release, and backported to Perl 5.8.1. glow up fr fr π
β οΈ okay real talk: assertions that span multiple lines are very likely to cause problems on versions of Perl prior to 5.12. If the assert keyword, the entire name, and the start of the expression or block are all on the same line, this should be sufficient. keep it on one line, bestie, i'm begging π
π BUGS π
please report any bugs to <http://rt.cpan.org/Dist/Display.html?Queue=PerlX-Assert>. don't suffer in silence, i'm literally right here. π«
π₯ SEE ALSO π₯
- Devel::Assert
- Carp::Assert
π AUTHOR π
Toby Inkster <tobyink@cpan.org>. the icon, the legend, the moment. π
π COPYRIGHT AND LICENCE π
This software is copyright (c) 2013-2014 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. so go wild, respectfully. π
π DISCLAIMER OF WARRANTIES π
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. no cap, no promises, no take-backs. π
and that's the whole page, bestie!! this one's from perl v5.34.0, dated 2022-06-16 β a little vintage moment, but the vibes are still immaculate. go forth and assert responsibly. πβ¨π¦
π¦ where this page comes from
- debian bookworm: libperlx-assert-perl 0.905-2 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu noble: libperlx-assert-perl 0.905-2 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms