http://www.perlmonks.org?node_id=542058


in reply to Re: RFC: Class::CGI
in thread RFC: Class::CGI

Your idea forces me to write wrapper objects for every object I want loaded,

Yes. However, as with good code, the handler only need to be written once and if it turns out that something was overlooked, it can easily be added and all code using the handler gets the new advanage.

... and you force me to implement the logic in new(). That would prevent me from putting the logic in my object itself.

I don't get what you're saying. Look at your counter-example:

constraints => { customer_name => { params => [ qw/ customer_name email age / ], constraint => sub { my ($name, $email, $age) = @_; # untaint, trim, whatever return My::Customer->find_or_create( ... ); } } }

In your example, customer_name is a declarative form of my handler. It's the same thing. And guess what? My handler reads pretty similarly:

package Customer::Handler; sub new { my ( $class, $cgi ) = @_; my ( $name, $email, $age ) = map { scalar $cgi->param($_) } qw/customer_name email age/; # untaint, trim, whatever return My::Customer->find_or_create( ... ); } 1;

There is, however, a huge difference here. Hand those two snippets to programmers who know nothing about the two modules and ask them what the code does. Mine builds on the knowledge programmers already have. There is nothing knew you need to learn for that handler. Once you understand that a handler is "a constructor which takes a CGI object and returns the appropriate instance", that's it. You're done. There's no going back to the docs to read that "constraints" means, or to figure out if "constraint_method_regexp_map" is what you really need.

In any event, I've no problem with DFV. It's a great module, it's just a different approach and I've never liked how much stuff I seem to have to wade through to figure out what I need.

Cheers,
Ovid

New address of my CGI Course.

Replies are listed 'Best First'.
Re^3: RFC: Class::CGI
by rhesa (Vicar) on Apr 08, 2006 at 19:54 UTC
    Ok, I'm throwing in the towel :)

    It wasn't my intention to champion DFV in the first place; you obviously have an itch to scratch; I know you write good code; and I suppose every module promoting safe CGI processing is a good one.

    I still have the feeling you're reinventing a wheel for which there already is a perfectly adequate implementation, but in the end, it's not my place to dissuade you from doing that.

    Good luck!
    rhesa