I wanted to build an awesome place for people to discuss module specific issues, but I don't have any more time for this, and there are much better places to discuss Perl-related issues. I'd recommend asking your question on Stack Overflow or on Perl Monks.
If you are looking for a Perl tutorial or Perl-related news, I hope these links will serve you well.
Posted on 2006-12-06 08:36:38-08 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
Direct Responses: Write a response