Actions Status Coverage Status MetaCPAN Release

NAME

Syntax::Keyword::Assert - assert keyword for Perl with zero runtime cost in production

SYNOPSIS

use Syntax::Keyword::Assert;

sub hello($name) {
    assert { defined $name };
    say "Hello, $name!";
}

hello("Alice"); # => Hello, Alice!
hello();        # => Dies when STRICT mode is enabled

DESCRIPTION

Syntax::Keyword::Assert introduces a lightweight assert keyword to Perl, designed to provide runtime assertions with minimal overhead.

STRICT Mode Control

The behavior of STRICT mode is controlled by the Devel::StrictMode module. You can enable or disable STRICT mode depending on your environment (e.g., development, testing, production).

For example, to enable STRICT mode:

BEGIN { $ENV{PERL_STRICT} = 1 }  # Enable STRICT mode

use Syntax::Keyword::Assert;
use Devel::StrictMode;

assert { 1 == 1 };  # Always passes
assert { 0 == 1 };  # Dies if STRICT mode is enabled

To disable STRICT mode (it is disabled by default):

use Syntax::Keyword::Assert;
use Devel::StrictMode;

assert { 0 == 1 };  # Block is ignored, no runtime cost

SEE ALSO: Bench

TIPS

Verbose error messages

If you set $Carp::Verbose = 1, you can see stack traces when an assertion fails.

use Syntax::Keyword::Assert;
use Carp;

assert {
    local $Carp::Verbose = 1;
    0;
}

SEE ALSO

LICENSE

Copyright (C) kobaken.

This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.

AUTHOR

kobaken kentafly88@gmail.com