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

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

Author

       kobaken <kentafly88@gmail.com>

perl v5.40.0                                       2024-12-21                       Syntax::Keyword::Assert(3pm)

Description

       Syntax::Keyword::Assert provides a syntax extension for Perl that introduces a "assert" keyword.

       By default assertions are enabled, but can be disabled by setting $ENV{PERL_ASSERT_ENABLED} to false
       before this module is loaded:

           BEGIN { $ENV{PERL_ASSERT_ENABLED} = 0 }  # Disable assertions

       When assertions are disabled, the "assert" are completely ignored at compile phase, resulting in zero
       runtime cost. This makes Syntax::Keyword::Assert ideal for use in production environments, as it does not
       introduce any performance penalties when assertions are not needed.

Keywords

assert
           assert(EXPR)

       If EXPR is truthy in scalar context, then happens nothing. Otherwise, it dies with a user-friendly error
       message.

       Here are some examples:

           assert("apple" eq "banana");  # => Assertion failed ("apple" eq "banana")
           assert(123 != 123);           # => Assertion failed (123 != 123)
           assert(1 > 10);               # => Assertion failed (1 > 10)

License

       Copyright (C) kobaken.

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

Name

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

See Also

       PerlX::Assert
           This  module  also  uses  keyword  plugin, but it depends on Keyword::Simple. And this module's error
           message does not include the failed expression.

       Devel::Assert
           This module provides a similar functionality, but it dose not use a keyword plugin.

Synopsis

           use Syntax::Keyword::Assert;

           my $obj = bless {}, "Foo";
           assert($obj isa "Bar");
           # => Assertion failed (Foo=HASH(0x11e022818) isa "Bar")

See Also