Help us improve
Share bugs, ideas, or general feedback.
From cpan-syntax-keyword-assert
Use Syntax::Keyword::Assert for zero-cost assertions in Perl
npx claudepluginhub kfly8/claude-cpan-plugins --plugin cpan-syntax-keyword-assertHow this skill is triggered — by the user, by Claude, or both
Slash command
/cpan-syntax-keyword-assert:skills/syntax-keyword-assertThe summary Claude sees in its skill listing — used to decide when to auto-load this skill
Syntax::Keyword::Assert provides an `assert` keyword for Perl with zero runtime cost when disabled.
Validates Perl scripts for syntax (perl -c/-wc), essential pragmas (strict/warnings/autodie), security issues (two-arg open/backticks/eval), best practices, and POD documentation.
Perl testing patterns using Test2::V0, Test::More, prove runner, mocking, coverage with Devel::Cover, and TDD methodology.
Applies modern Perl 5.36+ idioms like v5.36 pragma, subroutine signatures, postfix dereferencing, and isa operator for writing, reviewing, refactoring, and designing Perl applications.
Share bugs, ideas, or general feedback.
Syntax::Keyword::Assert provides an assert keyword for Perl with zero runtime cost when disabled.
assert EXPRuse Syntax::Keyword::Assert;
assert $x > 0;
assert $obj isa "MyClass";
assert defined $value;
# Dies with "Assertion failed" if expression is false
assert "apple" eq "banana"; # Dies: Assertion failed
When assertions are disabled, they are completely removed at compile time:
# In production with assertions disabled:
assert expensive_check(); # This code is completely removed
# Enable/disable assertions before module loading
$ENV{PERL_ASSERT_ENABLED} = 0; # Disable assertions
use Syntax::Keyword::Assert;
# Or keep default (enabled)
use Syntax::Keyword::Assert;
sub divide {
my ($a, $b) = @_;
assert defined $a && defined $b;
assert $b != 0;
return $a / $b;
}
sub process_user {
my $user = shift;
assert $user isa "User";
assert $user->can("get_name");
return $user->get_name();
}
sub complex_algorithm {
my @data = @_;
assert @data > 0;
my $result = process_data(@data);
assert defined $result;
assert ref($result) eq 'HASH';
return $result;
}
sub fibonacci {
my $n = shift;
# Precondition
assert $n >= 0;
my $result = $n <= 1 ? $n : fibonacci($n-1) + fibonacci($n-2);
# Postcondition
assert $result >= 0;
return $result;
}
# In deployment script or environment setup
BEGIN {
$ENV{PERL_ASSERT_ENABLED} = 0 if $ENV{PRODUCTION};
}
use Syntax::Keyword::Assert;
# All assertions are now compile-time no-ops
# Development-only assertions
use Syntax::Keyword::Assert;
sub critical_function {
my $data = shift;
# This assertion disappears in production
assert validate_complex_invariant($data);
return process($data);
}