Params-Validate - Using Attribute::Params::Validate and my own defined attributes

Posted on Wed Dec 6 10:36:38 2006 by gaetan
Using Attribute::Params::Validate and my own defined attributes

Hello all,

I created a method, using the Attribute::Params::Validate module to validate the parameters
sub my_method :method :Validate (foo => 1)

All worked fine

I added my own-defined attribute
use Attribute::Handlers; sub My_attr :ATTR(CODE) { no strict 'refs'; no warnings 'redefine'; my ($package, $symbol, $code) = @_; my $new_code = 'sub { print "This is my attribute"; } goto $code; } '; my $sub = eval $new_code; die $@ if $@; my $subname = $package . "::". *{$symbol}{NAME}; *{$subname} = $sub; }
My method "prototype" is now
sub my_method :method :Validate (foo => 1) :My_attr
When I call
$obj->my_method(foo => "toto");
I obtain the following error:
Odd number of parameters in call to Attribute::Params::Validate::__ANON__ when named parameters wer +e expected

When the Attribute::Params::Validate::Validate function is called on my_method, the call to attributes::get($referent) does not retrieve the "method" attribute, implying the previous error message.

Is there a way to use the Attribute::Params::Validate module with a user-defined attribute ?

Thanks Gaetan
Write a response