.\" -*- mode: troff; coding: utf-8 -*- .\" Automatically generated by Pod::Man 5.01 (Pod::Simple 3.43) .\" .\" Standard preamble: .\" ======================================================================== .de Sp \" Vertical space (when we can't use .PP) .if t .sp .5v .if n .sp .. .de Vb \" Begin verbatim text .ft CW .nf .ne \\$1 .. .de Ve \" End verbatim text .ft R .fi .. .\" \*(C` and \*(C' are quotes in nroff, nothing in troff, for use with C<>. .ie n \{\ . ds C` "" . ds C' "" 'br\} .el\{\ . ds C` . ds C' 'br\} .\" .\" Escape single quotes in literal strings from groff's Unicode transform. .ie \n(.g .ds Aq \(aq .el .ds Aq ' .\" .\" If the F register is >0, we'll generate index entries on stderr for .\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index .\" entries marked with X<> in POD. Of course, you'll have to process the .\" output yourself in some meaningful fashion. .\" .\" Avoid warning from groff about undefined register 'F'. .de IX .. .nr rF 0 .if \n(.g .if rF .nr rF 1 .if (\n(rF:(\n(.g==0)) \{\ . if \nF \{\ . de IX . tm Index:\\$1\t\\n%\t"\\$2" .. . if !\nF==2 \{\ . nr % 0 . nr F 2 . \} . \} .\} .rr rF .\" ======================================================================== .\" .IX Title "PerlX::Assert 3pm" .TH PerlX::Assert 3pm 2024-03-07 "perl v5.38.2" "User Contributed Perl Documentation" .\" For nroff, turn off justification. Always turn off hyphenation; it makes .\" way too many mistakes in technical documents. .if n .ad l .nh .SH NAME PerlX::Assert \- yet another assertion keyword .SH SYNOPSIS .IX Header "SYNOPSIS" .Vb 1 \& use PerlX::Assert; \& \& assert { 1 >= 10 }; .Ve .SH DESCRIPTION .IX Header "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. .PP However if, at compile time, any of the following environment variables is true, assertions are checked, and if they fail, throw an exception. .IP \(bu 4 \&\f(CW\*(C`PERL_STRICT\*(C'\fR .IP \(bu 4 \&\f(CW\*(C`AUTHOR_TESTING\*(C'\fR .IP \(bu 4 \&\f(CW\*(C`EXTENDED_TESTING\*(C'\fR .IP \(bu 4 \&\f(CW\*(C`RELEASE_TESTING\*(C'\fR .PP That is, assertions will only typically be checked when the test suite is being run on the authors' machine, or otherwise opted into. .PP The exact decision logic can be found in Devel::StrictMode. .PP You can also force assertions to be checked using: .PP .Vb 1 \& use PerlX::Assert \-check; .Ve .PP There are four syntaxes for expressing assertions: .PP .Vb 4 \& assert EXPR; \& assert { BLOCK }; \& assert "name", EXPR; \& assert "name" { BLOCK }; .Ve .PP 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 \f(CW\*(C`q\*(C'\fR or \f(CW\*(C`qq\*(C'\fR 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. .PP 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. .PP Assertions that span multiple lines are very likely to cause problems on versions of Perl prior to 5.12. If the \f(CW\*(C`assert\*(C'\fR keyword, the entire name, and the start of the expression or block are all on the same line, this should be sufficient. .SH BUGS .IX Header "BUGS" Please report any bugs to . .SH "SEE ALSO" .IX Header "SEE ALSO" Devel::Assert, Carp::Assert. .SH AUTHOR .IX Header "AUTHOR" Toby Inkster . .SH "COPYRIGHT AND LICENCE" .IX Header "COPYRIGHT AND LICENCE" This software is copyright (c) 2013\-2014 by Toby Inkster. .PP This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself. .SH "DISCLAIMER OF WARRANTIES" .IX Header "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.