Anyone know a perl module to validate object method arguments?
Like [
search.cpan.org...] but without the one-line restriction.
For example, I like this:
sub foo2 : Validate( foo => { type => ARRAYREF }, bar => { can => [ 'print', 'flush', 'frobnicate' ] }, baz => { type => SCALAR, callbacks => { 'numbers only' => sub { shift() =~ /^\d+$/ }, 'less than 90' => sub { shift() < 90 } } } )
{
...
}
Except for the fact that the stuff inside Validate(...) is all required to be on one line.
I really would like to use MooseX::Declare and types for this but alas cannot since this is for a production environment. For reference that looks like:
method deposit (Num $amount) {
$self->balance( $self->balance + $amount );
}
Which is just about one of the purtiest things I've seen. Num is a type - you can declare any kind of type.
Looking for either a stable module recommendation or ideas based on how you approach this sort of thing.
This is to be used in a large codebase so it would be nice if the validation were clean-looking, easy to maintain, etc.