homepage Welcome to WebmasterWorld Guest from 174.129.130.202
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Pubcon Platinum Sponsor 2014
Home / Forums Index / Code, Content, and Presentation / Perl Server Side CGI Scripting
Forum Library, Charter, Moderators: coopster & jatar k & phranque

Perl Server Side CGI Scripting Forum

    
Recommendations on how to validate method arguments wanted
Sorry, No Moose allowed
physics




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

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.

 

mattdw




msg:4171084
 9:32 pm on Jul 15, 2010 (gmt 0)

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?

physics




msg:4171129
 11:16 pm on Jul 15, 2010 (gmt 0)

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

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / Perl Server Side CGI Scripting
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved