On Fri, Jul 8, 2011 at 21:12, Cory Watson <jheep...@gmail.com> wrote:
> Ekki Plicht (DF4OR) wrote:
>>
>> Hi.
>> New to Moose, my first larger project with it.
>>
>> My object receives data from an external website, and that data needs
>> to be cleaned and sanitized a lot. Not wanting to create exotic custom
>> types for each data item, I tried to use 'around" method modifiers to
>> mangle the data.
>>
>> Example:
>> around 'kdnr' =>  sub {
>>     my ($org, $self, $value) = @_;
>>     return $self->kdnr unless $value;
>>
>> $debugcount++;
>> warn "in around kdnr $debugcount\n";
>>
>>     $value = '' unless ($value =~ m/\d{5}/);
>>     return $self->kdnr($value);
>> };
>
> Hey Ekki,
>
> You may want to check out the examples here:
>
> http://search.cpan.org/perldoc?Moose::Manual::MethodModifiers
>
> Check out the example in the Synopsis.

That's what I did. I thought.
My error was that I call $self->methodname from within the 'around'
modifier, which triggers the modifier again and again. Should have
used $self->$org instead.

Solved now, thanks!


> Also, keep in mind that you can use coercions:
>
> http://search.cpan.org/dist/Moose/lib/Moose/Cookbook/Basics/Recipe5.pod

Right, that's where I had an issue before. As a beginner with Moose I
abandoned my attempt and went with around modifiers for the time
being.

> Or, if you are validating input and such, you may prefer:
>
> http://search.cpan.org/perldoc?Data::Verifier

Ok. As much as I appreciate your work I would rather stay with my
approach for the moment, to gain more insights into Moose and such.
When I am feeling more confident with the basics of Moose I will look
at MooseX and other extensions like yours.

Cheers,
Ekki

Reply via email to