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

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

by tphyahoo (Vicar)
on Oct 18, 2005 at 11:24 UTC ( #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!

  • Comment on Params::Validate or Attribute::Params::Validate?

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.


    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; 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?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://500935]
Approved by Corion
Front-paged by diotalevi
[Discipulus]: i invented also 'gired'
[Lady_Aleena]: Discipulus, then that is a problem. I wanted to find total seconds of my entire .mp3 collection to do some math on it to see how many days of continuous music i have.
[LanX]: darn. .. I wanted to see Marine and Melonchon go to next round, just for fun xD
[Discipulus]: LA use Perl: traversing a dir tree is simple; foreach file mp3 $sec+= use Mp3::Info
[Lady_Aleena]: Discipulus, I was able to get the sum of the seconds on the command line using awk. Then I ran the result through a perl script and got the result. It came bach with 4 days, 9 hours, 56 minutes, 43 seconds.
[Lady_Aleena]: s/bach/back/;
[Discipulus]: gired anyway is the intermediate state between hired and fired (and vice versa;)
[Lady_Aleena]: Discipuluis, I don't know if I want to fight with File::Find. File::Find and I are not friends.
[Discipulus]: 4 day Bach is too muche even for me
[Discipulus]: LA you know who is paco?

How do I use this? | Other CB clients
Other Users?
Others chanting in the Monastery: (9)
As of 2017-04-23 20:32 GMT
Find Nodes?
    Voting Booth?
    I'm a fool:

    Results (432 votes). Check out past polls.