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?)



Edit: Cleaned up an *oops*

My code doesn't have bugs, it just develops random features.

Flame ~ Lead Programmer: GMS | GMS


In reply to New Module Consideration? by Flame

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.