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.

Also, keep in mind that you can use coercions:

http://search.cpan.org/dist/Moose/lib/Moose/Cookbook/Basics/Recipe5.pod

Or, if you are validating input and such, you may prefer:

http://search.cpan.org/perldoc?Data::Verifier



Reply via email to