standard and OOP together

G

Guy

I completed my Perl script in Notepad and it's only 22KBytes in size. It
works but it's ugly, and I'm going to rewrite it. If I decide to use the OO
interface of CGI.pm such as...

use CGI;
my $q = new CGI;
my $name = $q->param( "name" );

....could I still write the rest of my application in a standard way? I mean
what else would have to change?

Guy
 
A

A. Sinan Unur

I completed my Perl script in Notepad and it's only 22KBytes in size.
It works but it's ugly, and I'm going to rewrite it. If I decide to
use the OO interface of CGI.pm such as...

use CGI;
my $q = new CGI;
my $name = $q->param( "name" );

The CGI.pm docs annoy me by calling the CGI object 'query' and using the
indirect object syntax.

my $cgi = CGI->new;
...could I still write the rest of my application in a standard way? I
mean what else would have to change?

You need to call methods on the $cgi object thus created.

If you want to enforce the pure OO nature of the $cgi object, you might
want to use CGI::Simple (and move all HTML generation to
HTML::Template).

Sinan
--
A. Sinan Unur <[email protected]>
(remove .invalid and reverse each component for email address)

comp.lang.perl.misc guidelines on the WWW:
http://www.rehabitation.com/clpmisc/
 
C

ccc31807

I completed my Perl script in Notepad and it's only 22KBytes in size.  It
works but it's ugly, and I'm going to rewrite it.  If I decide to use the OO
interface of CGI.pm such as...

You may or not may be aware that typically Perl allows multiple ways
to do the same thing. Emitting HTML is one of those things that you
can do a number of different ways. I don't use CGI to emit HTML, I
don't like CGI for this purpose, and the following two paragraphs are
an attempt to justify my view. Note: most Perlists will disagree with
the following and find much fault with it, but you need to form your
own opinion. Don't take my word for it, but try it my way just for the
sake of comparison.

HTML (XHTML), and its attendants, CSS and JavaScript, have standard
specifications and their own validators. The specifications have as
their goal an absolute language standard which user interface agent
writers can rely on. I believe strongly in a strict adherence to the
standards, and that HTML authors should not cater to just one browser,
e.g., IE. In pursuit of this goal, I believe that HTML authors should
begin with hand written HTML (and CSS and JS) code written in a plain
text editor, like vi or notepad, and validating your code. Yes, if you
are in a production environment you will use an automated tool, like
Dreamweaver, but there is no substitute for the skills that
handwriting HTML gives you.

Everything I just said applies to HTML code emitted by Perl scripts.
After all, a CGI script is merely a program that spits out raw HTML,
CSS, and JS. The final judgment (if I may call it that) is the quality
of the HTML produced, not the pretty (or obfuscated) code written by
the programmers. Using CGI.pm tends to separate the programmer from
the HTML, and if you care about the quality of your HTML, you need to
see it as it is and without any intervening automation.

Okay, to modularize your code and avoid the cut-and-paste dance, you
will wind up writing functions to produce your HTML, which you will
call from other functions, until you have several layers, in essence
duplication in another fashion exactly what CGI does. HOWEVER -- it
isn't hard to do, and the bedrock on which you build your program is
STILL hand written HTML, and any time you want to look at it and alter
it, you can do so exactly as if you were hand writing HTML in vi or
notepad. The first time you run your HTML (the product of your CGI
script) through the validator and have it flag 127 errors, you will
understand exactly what I mean. You have an ironclad and direct
correlation between your HTML and your Perl script, and can track the
source of your HTML, CSS, and JS output.

For all its merits, CGI.pm doesn't give you this.

CC
 
M

Mordechai T. Abzug

Guy said:
If I decide to use the OO interface of CGI.pm such as... [snip]
...could I still write the rest of my application in a standard way?
I mean what else would have to change?

Nothing else need change. You can mix OO and imperative Perl.

- Morty
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top