Beefy Boxes and Bandwidth Generously Provided by pair Networks
Come for the quick hacks, stay for the epiphanies.
 
PerlMonks  

Re: validating sub arguments

by Herkum (Parson)
on Mar 02, 2007 at 17:23 UTC ( [id://602910]=note: print w/replies, xml ) Need Help??


in reply to validating sub arguments

I guess the question you should be asking, why is unsafe data getting passed to subroutines/methods in the first place.

For example you are writing a web page, you need to validate the data when 'Submit' the form's data. All data errors should have been caught at the point of submission, not at the point you are passing data into your routines or methods. After that, you initialize your environment to process the data.

It is best to have one really strong layer for validating data and catch exceptions in modules with diagnostic code. Avoid having multiple layers of validations in your programs; you end will end up having multiple layers for error handling and having to decide whether an error is because of data submitted or because there was a fatal exception in that subroutine/module.

As for validating form data, I use DataForm::Validator, it can be tough to learn at first as the documentation is not so great, but it really is very flexible.

Replies are listed 'Best First'.
Re^2: validating sub arguments
by bluto (Curate) on Mar 02, 2007 at 18:29 UTC
    I guess the question you should be asking, why is unsafe data getting passed to subroutines/methods in the first place.

    Perhaps from the programmer mistyping the argument list or misunderstanding the interface?

    Validating data from external sources is always needed. Validating data from internal sources is very useful during development and testing (ala C's assert()) and sometimes during production. Params::Validate has helped save me from my own bad memory/typing a number of times. It's not too hard to set it up so you can remove it from production code easily if that's what you want.

Re^2: validating sub arguments
by agianni (Hermit) on Mar 02, 2007 at 18:26 UTC

    Actually, I'm talking more about validating the arguments passed to a given subroutine, which may or may not be in the context of a Web application. Interestingly enough, though, I'm actually rather familiar with D::FV, as we use it for validating data for our Web applications. I had never thought about using that to validate the arguments to a given sub. It seems like cutting balsa wood with a power saw, but it certainly would be an option and it would be pretty easy to build the profiles on the fly.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://602910]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others exploiting the Monastery: (7)
As of 2024-04-19 12:57 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found