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.
| [reply] |
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)
| [reply] |
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.
| [reply] |
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 }' );
}
}
| [reply] [d/l] |
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. | [reply] |