smithery.ai

syntax-keyword-assert-perl

Use Syntax::Keyword::Assert for zero-cost assertions in Perl

First seen Mar 31, 2026

Installation

$ npx skills add https://smithery.ai

Similar popular skills

Related neighbors and high-traction skills in the same topics — useful to compare before installing.

Also in this package

Other skills from smithery.ai · top by installs.

npx skills add https://smithery.ai

Browse all from smithery.ai

More details

Agent compatibility

Declared targets from SKILL.md / docs. Unmarked agents are not listed — the skill may still install via the CLI.

Claude Code Not declared
Cursor Not declared
Codex Not declared
GitHub Copilot Not declared
Windsurf Not declared
Gemini CLI Not declared
Cline Not declared
OpenCode Not declared

Skill metadata

Parsed from SKILL.md frontmatter.

Version1.0.0

Package contents

Files included with this skill beyond the listing page.

  • skill md SKILL.md 2,880 B
  • docs SUMMARY.md 94 B

History

  1. First seen on skills.sh
  2. First recorded snapshot · 1 installs

SKILL.md

Syntax::Keyword::Assert - Zero-Cost Assertions

Syntax::Keyword::Assert provides an assert keyword for Perl with zero runtime cost when disabled.

Core Function

assert EXPR

use 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

Key Features

Zero Runtime Cost

When assertions are disabled, they are completely removed at compile time:

# In production with assertions disabled:
assert expensive_check();  # This code is completely removed

Environment Control

# 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;

Practical Examples

Input Validation

sub divide {
    my ($a, $b) = @_;
    
    assert defined $a && defined $b;
    assert $b != 0;
    
    return $a / $b;
}

Object Type Checking

sub process_user {
    my $user = shift;
    
    assert $user isa "User";
    assert $user->can("get_name");
    
    return $user->get_name();
}

Development Debugging

sub complex_algorithm {
    my @data = @_;
    
    assert @data > 0;
    
    my $result = process_data(@data);
    
    assert defined $result;
    assert ref($result) eq 'HASH';
    
    return $result;
}

Contract Programming

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;
}

Production Deployment

Disable in Production

# 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

Conditional Assertions

# 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);
}

Best Practices

  1. Use for debugging: Add assertions during development, disable in production
  2. Check invariants: Verify assumptions about data state and object types
  3. Validate inputs: Assert preconditions for function parameters
  4. Document assumptions: Assertions serve as executable documentation
  5. Zero-cost safety: Enable aggressive checking without production performance penalty