darren chamberlain <[EMAIL PROTECTED]> writes:

> Chip Turner ([EMAIL PROTECTED]) said something to this effect on 05/23/2001:
> > If I could make a suggestion -- don't depend upon a CGI.pm interface
> > for form variables.  Abstract it away.  One option would be to use
> > closures:
> 
> I agree with not relying upon CGI, but using closures still
> requires some knowledge of the object type. Something simpler
> would be to assume that an object passed in has a param method
> that behaves the way CGI.pm's and Apache::Request's param do.
> Something like:

Not true at all.

my $cgi = new CGI;
my $cgi_param = sub { return $cgi->param(shift) };
my $asp_param = sub { return $Request->{+shift} };
etc

The nice thing about closures is they could hide any interface at all
behind them; all that is required is that the function that generates
the closure follow the very simple convention of "return the formvar
of the name starting with the first parameter you're called with."
There is absolutely no reliance upon the underlying object structure.
What you're suggesting is equivalent to assuming the object is derived
from some kind of base class that supports the param() method though
without actually having to be ISA of that class.  That's naughty OO
programming :)  Just because perl lets you be typeless doesn't mean
it's always in the best interest of clean design to do so.

Closures are excellent in hiding implementation details of simple
operations, and I think in this case they fit quite well.  The system
can even be written to work just fine without the user using closures
if they're using CGI.pm, as in my previous example.

Chip

-- 
Chip Turner                   [EMAIL PROTECTED]
                              RHN Web Engineer

Reply via email to