I'm thinking of writing a new module to do what Data::FormValidator and Data::Validator::Item and a few other modules have done.
The question I'm sure you're already asking is, "Why? It's already been done!"
My reply is, "Yes, it's already been done, in fact it's already been done at least 7 times"
"Then why are you doing it again?"
"Because I think I can do it better."
"Well that's a self-rightious attitude. Why could you do it better?"
"Because I'm going to do it differently."
"Is differently better?"
"No, but this time I think it might be... see for yourself:"
Sample of code using new data validation package:use CGI; use Data::Validate::OO; #EEK! We all know what that OO means! use strict; #of couse use warnings; #ditto #I'm making an instance of it... obviously... my $checker = new Data::Validate::OO( -failure => sub { my($field,$data) = @_; print "Data $data in $ +field illegal!"; } ); $checker->newrule( -name => 'homephone', -element => 'phone', #Not required, defaults to name -tests => { -custom =>[ qr/^\d{3}[\-\s]?\d{3}[\-\s]?\d{4}$/, #sorry if that's not qui +te right, writing it on the fly ], }, ); $checker->newrule( -name => 'name', -tests => { -custom => [ qr/\w*\s*\w\.?\s*\w*/, ], } ); $checker->newrule( -name=>'mail', -required => 0, #Defaults to 1, not required, still complains if da +ta is there but fails tests -tests => { -def => 'email', #Use a built-in check for valid email -custom =>[ sub{ my $data = shift; if($data =~ m/\@hotmail\.com$/){ return; } return 1; } ], } ); #Ok, we have a simple check now, try using it. my $CGI = new CGI; my $status = $checker->test($CGI->param()); #Testing incoming form dat +a! #or my $status = $checker->test(name=>'John R. Doe',phone=>'000-111-2345', +mail=>'me@myhost.com'); #This should result in nothing being printed, and true being returned my $status = $checker->test(name=>'a',phone=>'3553451634',mail=>'me@my +host.com'); #Would complain about the name and return false my $status = $checker->test(name=>'My R. Name',phone=>'344-234-2525',m +ail=>'u@hotmail.com'); #Would fail because even though an email is no required, it was not on +e that could be accepted (not empty or valid) my $status = $checker->test(name=>'Your A. Name',phone=>'1323445432'); #This would pass because the email is not defined #Now that you know the data is or is not valid, do something!
Note: The above was just spontaniously written, with no thought as to the accuracy of any of the regex expressions or other assorted mistakes. If I'm wrong... oops... go ahead and point it out, but give your opinion at the same time!
So there's my idea, it's very similar to what already exists, but I feel that in some way it's better, perhaps because of the easier methods of adding custom checks. Obviously there is some more syntax planned for the rules definitions, as well as using the 'name' to allow the adition and deletion/editing of rules (needed it for one set, but no need for another trial).
Now the reason for this post, is this something the community would like, or would it just be wasing space on CPAN doing something that several other modules already do? Basically, should I spend the time to make this idea happen? (For that matter, is there already a package that does this exactly as it'm describing it?)
My code doesn't have bugs, it just develops random features.
In reply to New Module Consideration? by Flame
For: | Use: | ||
& | & | ||
< | < | ||
> | > | ||
[ | [ | ||
] | ] |