in reply to OO CGI vs. function-oriented
probably one of the easiest to understand reasons for using an OO interface over the function oriented one is to prevent namespace pollution.
if you're using the function oriented interface, you have to be careful that nowhere in your code do you have a subroutine named 'param', or 'upload', or 'header' or any of the other functions that CGI defines. so first of all, you have to be familiar enough with the CGI module to know the full list of functions it exports, then you have to be careful to avoid them in your own code, then you have to be careful that any other modules you use don't export functions with those names. the last part is the real kicker, especially since it makes it more difficult to add modules in the future.
on the other hand, if you're using the OO interface, you can just do
my $cgi = new CGI(); my $foo = $cgi->param('foo'); print $cgi->header(); ¶m($foo); &header($foo); ... sub param { ... } sub header { ... }
and know that your param and header subs will never get confused with CGI's.
personally, i find that using the OO interfaces to modules looks cleaner and easier to read, as long as things are named well. you always have the '$cgi->' there to give you a hint that the function being called is something to do with CGI.
|
|---|