Acme::CPANLists::PERLANCAR::Assert - Assertion
This document describes version 0.21 of Acme::CPANLists::PERLANCAR::Assert (from Perl distribution Acme-CPANLists-PERLANCAR), released on 2017-06-19.
Assertion is a check statement that must evaluate to true or it will abort program's execution. It is useful during development/debugging:
assert("there must be >3 arguments", sub { @args > 3 });
In production code, compilers ideally do not generate code for assertion statements so they do not have any impact on runtime performance.
In the old days, you only have this alternative to do it in Perl:
assert(...) if DEBUG;
where DEBUG is a constant subroutine, declared using:
DEBUG
use constant DEBUG => 0;
or:
sub DEBUG() { 0 }
The perl compiler will optimize away and remove the code entirely when DEBUG is false. But having to add if DEBUG to each assertion is annoying and error-prone.
if DEBUG
Nowadays, you have several alternatives to have a true, C-like assertions. One technique is using Devel::Declare (e.g. PerlX::Assert). Another technique is using B::CallChecker (e.g. Assert::Conditional).
Assert::Conditional
PerlX::Assert
Devel::Assert
Please visit the project's homepage at https://metacpan.org/release/Acme-CPANLists-PERLANCAR.
Source repository is at https://github.com/perlancar/perl-Acme-CPANLists-PERLANCAR.
Please report any bugs or feature requests on the bugtracker website https://rt.cpan.org/Public/Dist/Display.html?Name=Acme-CPANLists-PERLANCAR
When submitting a bug or request, please include a test-file or a patch to an existing test-file that illustrates the bug or desired feature.
Acme::CPANLists - about the Acme::CPANLists namespace
acme-cpanlists - CLI tool to let you browse/view the lists
perlancar <perlancar@cpan.org>
This software is copyright (c) 2017, 2016, 2015 by perlancar@cpan.org.
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.
To install Acme::CPANLists::PERLANCAR, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Acme::CPANLists::PERLANCAR
CPAN shell
perl -MCPAN -e shell install Acme::CPANLists::PERLANCAR
For more information on module installation, please visit the detailed CPAN module installation guide.