develooper Front page | perl.moose | Postings from July 2011

[Newb] Mangling parameters, avoiding recursions?

Thread Next
July 8, 2011 12:04
[Newb] Mangling parameters, avoiding recursions?
Message ID:
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.

around 'kdnr' => sub {
    my ($org, $self, $value) = @_;
    return $self->kdnr unless $value;

warn "in around kdnr $debugcount\n";

    $value = '' unless ($value =~ m/\d{5}/);
    return $self->kdnr($value);

This item must be 5 digits, or not present at all, but our customers
manage to enter all kinds of creative stuff here. Checking on the
website is no option, so I want to do it here.

When reading the data set the debugcounter skyrockets within seconds,
a little bit later I get a "Deep recursion" error and much later the
process is killed.

I am aware that 'around' methods probably aren't the best place to
sanitize data, but how else? Custom types? I have seen a Module
MooseX::Mangle, but I am not sure if this does help me with that
recursion thing.

Ideas, hints? Fundamental misunderstanding on my side when using Moose?


Thread Next Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About