Ricardo SIGNES 😄


Sub::MicroSig - microsigs for microvalidation of sub arguments


version 0.032


  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.

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.


Ricardo Signes, <rjbs@cpan.org>


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


Please report any bugs or feature requests to bug-sub-microsig@rt.cpan.org, or through the web interface at http://rt.cpan.org. I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.



Copyright 2005-2006 Ricardo SIGNES. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.