Attribute-Validate
view release on metacpan or search on metacpan
lib/Attribute/Validate.pm 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.
=head2 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.
=head2 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.
=head2 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.
=head1 EXPORTABLE SUBROUTINES
=head2 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.
=head1 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
=head1 CONFIGURATION AND ENVIRONMENT
If your OS Perl is too old perlbrew can be used instead.
=head1 BUGS AND LIMITATIONS
Enchanting anonymous subroutines with attributes won't allow them to be used by this module because of limitations of the language.
=head1 LICENSE AND COPYRIGHT
This software is Copyright (c) 2025 by Sergio Iglesias.
This is free software, licensed under:
The MIT (X11) License
=head1 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 L<mailto:sergioxz@cpan.org>.
=head1 INCOMPATIBILITIES
None known.
=head1 VERSION
0.0.x
=head1 AUTHOR
Sergio Iglesias
=cut
( run in 3.666 seconds using v1.01-cache-2.11-cpan-39bf76dae61 )