Acme-CPANModules-Assert

 view release on metacpan or  search on metacpan

lib/Acme/CPANModules/Assert.pm  view on Meta::CPAN

package Acme::CPANModules::Assert;

use strict;

our $AUTHORITY = 'cpan:PERLANCAR'; # AUTHORITY
our $DATE = '2022-03-08'; # DATE
our $DIST = 'Acme-CPANModules-Assert'; # DIST
our $VERSION = '0.002'; # VERSION

our $LIST = {
    summary => 'List of modules to do assertion',
    description => <<'_',

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:

    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.

Nowadays, you have several alternatives to have a true, C-like assertions. One
technique is using <pm:Devel::Declare> (e.g. <pm:PerlX::Assert>). Another technique is
using <pm:B::CallChecker> (e.g. <pm:Assert::Conditional>).

_

        entries => [
            {module=>'Assert::Conditional'},
            {module=>'PerlX::Assert'},
            {module=>'Devel::Assert'},
            #{module=>'assertions'}, # this module doesn't work now, it uses an experimental feature available on 5.9.x which finally removed before 5.10.
        ],
    };

1;
# ABSTRACT: List of modules to do assertion

__END__

=pod

=encoding UTF-8

=head1 NAME

Acme::CPANModules::Assert - List of modules to do assertion

=head1 VERSION

This document describes version 0.002 of Acme::CPANModules::Assert (from Perl distribution Acme-CPANModules-Assert), released on 2022-03-08.

=head1 DESCRIPTION

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 C<DEBUG> is a constant subroutine, declared using:

 use constant DEBUG => 0;

or:

 sub DEBUG() { 0 }

The perl compiler will optimize away and remove the code entirely when C<DEBUG>
is false. But having to add C<if DEBUG> to each assertion is annoying and
error-prone.

Nowadays, you have several alternatives to have a true, C-like assertions. One
technique is using L<Devel::Declare> (e.g. L<PerlX::Assert>). Another technique is
using L<B::CallChecker> (e.g. L<Assert::Conditional>).

=head1 ACME::CPANMODULES ENTRIES

=over

=item * L<Assert::Conditional> - conditionally-compiled code assertions

Author: L<TOMC|https://metacpan.org/author/TOMC>

=item * L<PerlX::Assert> - yet another assertion keyword

 view all matches for this distribution
 view release on metacpan -  search on metacpan

( run in 0.939 second using v1.00-cache-2.02-grep-82fe00e-cpan-2c419f77a38b )