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 ;-)


In reply to Re: why use OO nature in CGI? by cLive ;-)
in thread why use OO nature in CGI? by sulfericacid

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.