Syntax...:Assert(3pm)
π Syntax...:Assert(3pm) π
okay bestie, so this is the manual page for Syntax::Keyword::Assert β a User Contributed Perl Documentation joint, and honestly? it's giving zero runtime cost and we're obsessed. π
β¨ NAME β¨
Syntax::Keyword::Assert β it's an assert keyword for Perl, and the whole point is that it costs you literally nothing at runtime. no cap. π«Ά
πΈ SYNOPSIS πΈ
use Syntax::Keyword::Assert;
my $obj = bless {}, "Foo";
assert($obj isa "Bar");
# => Assertion failed (Foo=HASH(0x11e022818) isa "Bar")
assert($x > 0, "x must be positive");
# => x must be positive
like look at that error message. it's so helpful. it tells you the actual expression that flopped. iconic behaviour fr fr. π
π¦ DESCRIPTION π¦
okay so Syntax::Keyword::Assert is a syntax extension for Perl, and what it does is add an assert keyword into your life. that's it. that's the vibe. β¨
By default, assertions are enabled. but β plot twist β you can turn them off by setting $ENV{PERL_ASSERT_ENABLED} to false before this module gets loaded:
BEGIN { $ENV{PERL_ASSERT_ENABLED} = 0 } # Disable assertions
β οΈ note the before it's loaded part, bestie. the BEGIN block is doing the heavy lifting here. don't come crying to me if you set it after. π
When assertions are disabled, the assert are completely ignored at compile phase, which results in zero runtime cost. that's the moment. π
This is what makes Syntax::Keyword::Assert ideal for use in production environments β because it does not introduce any performance penalties when assertions are not needed. your prod boxes stay fast, your dev boxes stay loud. main character energy. π
π KEYWORDS π
π assert
assert(EXPR)
assert(EXPR, MESSAGE)
If EXPR is truthy in scalar context, then happens nothing. like, literally nothing. silence. tranquility. π§
Otherwise? it dies with a user-friendly error message. π (politely, though. user-friendly, remember.)
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)
You can also hand it a custom error message as the second argument:
assert($x > 0, "x must be positive");
# => x must be positive
now here's the good part β the message expression is lazily evaluated. it only gets evaluated when the assertion fails. so it's equivalent to:
$cond || do { die $msg }
which means you can go absolutely feral and put expensive computations or side effects in that message without worrying about performance when the assertion passes:
assert($x > 0, expensive_debug_info());
# expensive_debug_info() is NOT called if $x > 0
NOT called. bestie. that's the whole flex. π₯
π SEE ALSO π
PerlX::Assertβ this one also uses a keyword plugin, but it depends onKeyword::Simple. and its error message does not include the failed expression. (so you don't get the receipts. tragic.) πDevel::Assertβ gives you similar functionality, but it does not use a keyword plugin.
π 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>
and that's the whole page, bestie!! go assert something. responsibly. π
mwah π β this was perl v5.42.3, dated 2026-08-20, and you just read Syntax...:Assert(3pm). slay. πΈβ¨
π¦ where this page comes from
- ubuntu stonking: libsyntax-keyword-assert-perl 0.19-1build1 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms