Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

Params::Validate or Attribute::Params::Validate?

by tphyahoo (Vicar)
on Oct 18, 2005 at 11:24 UTC ( [id://500935]=perlquestion: print w/replies, xml ) Need Help??

tphyahoo has asked for the wisdom of the Perl Monks concerning the following question:

Seems like Params::Validate and Attribute::Params::Validate are two ways of accomplishing the same thing. The second is basically a front end... right?

Well, I have been intending to start incorporating these modules into my toolset, since I believe it will make for more maintainable code.

I'd just like to hear if some monks like one style of doing this better than the other and why. Thanks!

Replies are listed 'Best First'.
Re: Params::Validate or Attribute::Params::Validate?
by xdg (Monsignor) on Oct 18, 2005 at 11:54 UTC

    Attribute::Params::Validate uses Attribute::Handlers. While I haven't testing this out, I suspect it breaks in any module that defines its own attribute handlers instead of using Attribute::Handlers. For example, Class::Std (see Class::Std : How does MODIFY_HASH_ATTRIBUTES work? -- in addition to lack of thread safety, yet another reason to be careful using it).

    Params::Validate works just fine. I also find it useful to be able to define some default specs in one place and use it many times. With the attribute version, you always have to put the spec in the attribute line.

    -xdg

    Code written by xdg and posted on PerlMonks is public domain. It is provided as is with no warranties, express or implied, of any kind. Posted code may not have been tested. Use of posted code is at your own risk.

Re: Params::Validate or Attribute::Params::Validate?
by rinceWind (Monsignor) on Oct 18, 2005 at 16:16 UTC

    Note that Attribute::Params::Validate ships with Params::Validate.

    So far, I've never needed to use the handlers form; Params::Validate has been perfectly adequate for my needs. However, I've found that not everybody likes Params::Validate, and I've had cases of people choosing not to use my CPAN modules owing to dependency on P::V. This inspired me to come up with Module::Optional including Params::Validate::Dummy, which allows people to still use code with calls to validate(), validate_pos() etc. without installing P::V.

    Not all of my CPAN modules that use Params::Validate have been changed to use Module::Optionsl yet, but this is something I intend to incorporate on their next release.

    --

    Oh Lord, won’t you burn me a Knoppix CD ?
    My friends all rate Windows, I must disagree.
    Your powers of persuasion will set them all free,
    So oh Lord, won’t you burn me a Knoppix CD ?
    (Missquoting Janis Joplin)

      I'm curious -- do you know why some people are so averse to Params::Validate as to avoid modules that depend on it? Do they think it doesn't work, or is cripplingly slow? Do they just avoid all XS?

      It doesn't use source filters or have exotic dependencies; reviews on CPAN ratings are good; there's nothing damning in rt.cpan.org; one Perlmonks node is the only bad I can find about it.

      In Regexp::NamedCaptures, I wrote this snippet so that P::V would be used if it was available and dummied up into place if it wasn't. I have half a mind to make that become a P::V::Fake and just include that with the distribution tarballs of my modules. My Build.PL recommends P::V and my Makefile.PL is silent on the matter.

      BEGIN { eval { require Params::Validate; Params::Validate->import( 'validate_pos', 'SCALAR', 'UNDEF', 'CODEREF' ); }; if ( $@ ) { eval( 'sub validate_pos (\@@) { @{$_[0]} }' . 'sub SCALAR () { 0 }' . 'sub UNDEF () { 0 }' . 'sub CODEREF () { 0 }' ); } }
Re: Params::Validate or Attribute::Params::Validate?
by perrin (Chancellor) on Oct 18, 2005 at 14:43 UTC
    I expect the attribute handlers will be slower, more likely to break, and really ugly when your rules get complex. Params::Validate has been great though, and I highly recommend it.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://500935]
Approved by Corion
Front-paged by diotalevi
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (5)
As of 2024-03-29 13:42 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found