logo
Free, unlimited AI code reviews that run on commit
git-lrc git-lrc GitHub Install Now We'd appreciate a star git-lrc - Free, unlimited AI code reviews that run on commit | Product Hunt git-lrc - Free, unlimited AI code reviews that run on commit | Product Hunt

PerlX::Assert - yet another assertion keyword

Author

       Toby Inkster <tobyink@cpan.org>.

Bugs

       Please report any bugs to <http://rt.cpan.org/Dist/Display.html?Queue=PerlX-Assert>.

Description

       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.

       •   "PERL_STRICT"

       •   "AUTHOR_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 otherwise opted into.

       The exact decision logic can be found in Devel::StrictMode.

       You can also force assertions to be checked using:

          use PerlX::Assert -check;

       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); general expressions are not supported because Text::Balanced is used to
       parse the assertion name. An assertion is a statement, so must be followed by a semicolon unless it's the
       last statement in a block.

       PerlX::Assert was originally distributed as part of Moops, but was fairly independent of the rest of  it,
       and has been spun off as a separate release, and backported to Perl 5.8.1.

       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.

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.

perl v5.40.1                                       2025-08-15                                 PerlX::Assert(3pm)

Name

       PerlX::Assert - yet another assertion keyword

See Also

       Devel::Assert, Carp::Assert.

Synopsis

          use PerlX::Assert;

          assert { 1 >= 10 };

See Also