Welcome to WebmasterWorld Guest from 23.22.19.253

Forum Moderators: coopster & jatar k & phranque

Message Too Old, No Replies

Recommendations on how to validate method arguments wanted

Sorry, No Moose allowed

   
8:49 pm on Jul 15, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



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.
9:32 pm on Jul 15, 2010 (gmt 0)

5+ Year Member



I know this isn't helpful towards your end goal, so I apologize for that, but I'm curious why can't you use Moose for this project? You mention it is for a production environment, but is the limiting factor because you can't install all of the Moose(X) modules or concerns over stability?
11:16 pm on Jul 15, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



mattdw, let's just say I'd LOVE to use Moose. I've used it before on other projects but can't now. There are performance concerns, there is already a lot of production code that would have to be refactored if we standardized on Moose, and yes the MooseX modules aren't supposed to be ready for prime time.
If it were just up to me we'd use Moose but it isn't so am looking for the next-best way to approach this...