While writing CGI::Search, I wanted to make validating CGI input a very basic part of the module (making it so integerated into it that there'd be no excuse for not doing it). As a general rule, the data would be untainted after coming out of validation (though the module itself doesn't do much that would require untainting). There were a few built-in validators, but I wanted users to be able to create their own.

My initial thought was to pass in a regex match (via qr//). However, while regexen might be rather powerful, they just aren't good enough.

The real solution was to pass in a referance to a subroutine. There are a few requirements that a custom validator must have (takes in the data to be validated as its only argument, returns a three-element list (a boolean value indicating success or failure, the untainted data (if successful), and a string that can be used as an error message on failure)).

Later, I discovered the WWW::FieldValidator module. This takes things further than CGI::Search does, in that you can specify the use of either some built-in validation, a regex match, or a subroutine referance. Also, you can pass in an array ref containing mutilple validators, so that a single peice of data must mach all the validators you pass. Replacing CGI::Search's validation sementics with WWW::FieldValidator is on my TODO list.

Finally getting to the point--like many things in software, flexibility is a more evolutionary process than something that comes in a flash of insight. Using a regex wasn't quite powerful enough, but it was simple. Subroutines were powerful, but lost much of the simplicity. The real soultion, as WWW::FieldValidator showed me, was to support both.

----
I wanted to explore how Perl's closures can be manipulated, and ended up creating an object system by accident.
-- Schemer

Note: All code is untested, unless otherwise stated


In reply to Re: Multilevel flexibillity by hardburn
in thread Multilevel flexibillity by zby

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.