Attribute-Validate

 view release on metacpan or  search on metacpan

README.md  view on Meta::CPAN

    only_use_in_list_context(); # Dies
    my @list = only_use_in_list_context(); # Works

Enforces the caller to use the subroutine in List Context to prevent errors and misunderstandings.

## NoListContext

    sub never_use_in_list_context: NoListContext {
        return 'scalar_or_void';
    }
    my $list = never_use_in_list_context(); # Works
    never_use_in_list_context(); # Works
    my @list = never_use_in_list_context(); # Dies

Enforces the caller to never use the subroutine in List Context to prevent errors and misunderstandings.

## ScalarContext

    sub only_use_in_scalar_context: ScalarContext {
        return 'hey';
    }
    my @scalar = only_use_in_scalar_context(); # Dies
    only_use_in_scalar_context(); # Dies
    my $scalar = only_use_in_scalar_context(); # Works

Enforces the caller to use the subroutine in Scalar Context to prevent errors and misunderstandings.

## NoScalarContext

    sub never_scalar_context: NoScalarContext {
        return @array;
    }
    my @list = never_scalar_context(); # Works
    never_scalar_context(); # Works
    my $scalar = never_scalar_context(); # Dies

Enforces the caller to never use the subroutine in Scalar Context to prevent errors and misunderstandings.

# EXPORTABLE SUBROUTINES

## anon\_requires

    my $say_thing = anon_requires(sub($thing) {
        say $thing;
    ), Str);

    my $say_thing = anon_requires(sub($thing) {
        say $thing;
    }, \%spec, Str);

Enforces types into anonymous subroutines since those cannot be enchanted using attributes.

# DEPENDENCIES

The module will pull all the dependencies it needs on install, the minimum supported Perl is v5.16.3, although latest versions are mostly tested for 5.38.2

# CONFIGURATION AND ENVIRONMENT

If your OS Perl is too old perlbrew can be used instead.

# BUGS AND LIMITATIONS

Enchanting anonymous subroutines with attributes won't allow them to be used by this module because of limitations of the language.

# LICENSE AND COPYRIGHT

This software is Copyright (c) 2025 by Sergio Iglesias.

This is free software, licensed under:

    The MIT (X11) License

# CREDITS

Thanks to MultiSafePay and the Tech Leader of MultiSafePay for agreeing in creating this CPAN module inspired in a similar feature in their codebase, this code was inspired by code found there, but was
written without the code in front from scratch.

MultiSafePay is searching for Perl Developers for working in their offices on Estepona on Spain next to the beach, if you apply and do not get a reply and you think you are a 
experienced/capable enough Perl Developer drop me a e-mail so I can try to help you get a job [mailto:sergioxz@cpan.org](mailto:sergioxz@cpan.org).

# INCOMPATIBILITIES

None known.

# VERSION

0.0.x

# AUTHOR

Sergio Iglesias



( run in 2.784 seconds using v1.01-cache-2.11-cpan-39bf76dae61 )