in reply to why use OO nature in CGI?
The most common reason for me is modules. Let's say I have a script that uses a module I've written, and that module uses CGI (for whatever reasons). And let's say I want to use a second module that also uses CGI. There are several situations where, if both are using params sent via post that you will get burnt, because the content buffer only gets read once when creating the first CGI object.
So I have a method in a common module like this:
sub new_CGI { defined $Module::CGI or $Module::CGI = CGI->new(); return $Module::CGI; }
and in each module, I just call the new_CGI method:
my $q = Module::new_CGI;
I actually use OO for this in RL something like this (very stripped down), passing the common module as an argument:
use Module; use ModB; use ModC; my $m = Module->new(); my $mb = ModB->new($m); my $mc = ModC->new($m);
I also use the common module to throw database handles around too. It took me forever to work out this problem initially, but now I find it a very tidy way to use modules already used.
cLive ;-)
|
|---|