Sub::MicroSig - microsigs for microvalidation of sub arguments
version 0.033
use Sub::MicroSig; sub pow :Sig($x $pow; $trunc) { my $arg = shift; my $value = $arg->{x} ** $arg->{pow}; $value = int $value if $arg->{trunc}; } ... pow({ pow => 2, x => 4 }); # 64 pow([ 2, 0.5, 1 ]); # 1 # int(sqrt(2))
This module allows you to give subroutine a signature using Params::Validate::Micro.
To provide a signature to a subroutine, provide the attribute :Sig(), enclosing in the parentheses a valid Params::Validate::Micro argument string.
:Sig()
The routine will be wrapped so that its parameters are rewritten into the result of calling micro_validate on its passed arguments. If more than one argument is passed, or if the one passed argument is not an array or hash reference, an exception is thrown by Sub::MicroSig.
micro_validate
The the given arguments cannot be validated according to the micro-argument string, Params::Validate throws an exception.
To attach a signature to a method, use the :MethodSig() attribute. It will check that the invocant ($_[0]) is something on which a method could be called and then pass the rest of the stack on for normal micro-validation.
:MethodSig()
$_[0]
Thanks, Hans Dieter Pearcey! You wrote Params::Validate::Micro, and refrained from wincing when I suggested this would be a nice use of it.
Params::Validate::Micro
Params::Validate
Ricardo SIGNES <rjbs@cpan.org>
This software is copyright (c) 2005 by Ricardo SIGNES.
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.
To install Sub::MicroSig, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Sub::MicroSig
CPAN shell
perl -MCPAN -e shell install Sub::MicroSig
For more information on module installation, please visit the detailed CPAN module installation guide.