Ricardo SIGNES

NAME

Sub::MicroSig - microsigs for microvalidation of sub arguments

VERSION

version 0.033

SYNOPSIS

  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))

DESCRIPTION

This module allows you to give subroutine a signature using Params::Validate::Micro.

USAGE

To provide a signature to a subroutine, provide the attribute :Sig(), enclosing in the parentheses a valid Params::Validate::Micro argument string.

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.

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.

THANKS

Thanks, Hans Dieter Pearcey! You wrote Params::Validate::Micro, and refrained from wincing when I suggested this would be a nice use of it.

SEE ALSO

AUTHOR

Ricardo SIGNES <rjbs@cpan.org>

COPYRIGHT AND LICENSE

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.