in reply to variables as classes

While it would be possible to create a class to encapsulate the behaviour, or a tied variable that forbids storage of non-email addresses.. I don't think it is particularly wise to do so.

Why not just validate the user input early on, and send them back to the form entry if they do not provide an email address? I am fond of using Data::FormValidator and HTML::FillInForm for this. If you use CGI::Application then CGI::Application::Plugin::ValidateRM encapsulates this behaviour for you quite nicely.

Replies are listed 'Best First'.
Re^2: variables as classes
by nmerriweather (Friar) on Sep 04, 2006 at 06:04 UTC
    I already do that for user submitted data.

    I need this functionality for data that is coming out of my database, that I perform various markup or logic operations on. If I pull an email address out of the DB, all of my various functions still check it to verfiy that it is an email when they're passed it.

    I don't want to accidentally send an email to a non-email, or turn a non-http address into an href. Those functions need to catch errors, and every function I write checks the input data.

    With some custom classes, I can just check the ISA before running a regex. thats way more efficient than running a regex over and over again. And if I'm not using a class, but a string, then I just run the regex.