Hi all,

A long time ago I toyed with the idea of treating HTML forms as object
collections.nnI've gone ahead and written an alpha which you can read
about at http://www.perlmonks.org/?node_id=541983

Note that one of my replies covers some changes which I have not
uploaded yet, but in a nutshell, you can do stuff like this:

  use Class::CGI
    handlers => {
      customer => 'Class::CGI::Customer',
      date     => 'My::Date::Handler',
    };

  my $cgi  = Class::CGI->new;
  my $cust = $cgi->param('customer');
  my $date = $cgi->param('date');

  my $name = $cust->name; # look ma, objects!
  my $year = $date->year;

The handlers are ridiculously easy to write and they encapsulate
everything they need to know for building those objects.  In fact,
there may not even be a real "date" param, but just "year", "month" and
"date" fields.  Or maybe there is a "date" param and the handler can
handle either that or the aforementioned fields.  No matter how you set
things up, your end user merely calls $cgi->param('date') and
everything is handled transparently, right down to the data validation
and untainting.

This makes it very easy to provide a handler to all of your scripts and
classes.  Further, using handlers extensively means you're more likely
to use consistent parameter names throughout your site, making your
code more maintainable.

Of course, you can still call $cgi->raw_param('customer') to get the
actual value without driving it through the handler.

You can also set handlers on Class::CGI instances in case you're
working in a persistent environment and you don't want all of your code
to use the same handlers for the same parameters.

Comments, thoughts and suggestions are welcome.

Cheers,
Ovid

-- 
If this message is a response to a question on a mailing list, please send 
follow up questions to the list.

Web Programming with Perl -- http://users.easystreet.com/ovid/cgi_course/

Reply via email to