On Sat, 19 May 2001, Larry Leszczynski wrote:

> Hi all -
>
> Just curious because it seems to come up a lot - for what applications
> have people run into a serious need for HTML generators ala CGI.pm?  (I'm
> not talking about templating systems, there's obvious need and practical
> use for those.)
>
> It seems like people like to use the HTML generating features of CGI.pm.
> I've generated a lot of HTML, and I haven't run into any situations where
> I would do something like this:
>
> >    print table(
> >        -align => "center",
> >        tr(
> >            td( "foo" ),
> >            td( "bar" ),
> >        ),
> >    ) ;
>
> instead of just doing this:
>
> print <<EOF;
>    <table align="center">
>    <tr>
>       <td>foo</td>
>       <td>bar</td>
>    </tr>
>    </table>
> EOF
>
> Seems like the same amount of typing, it's easier (for me anyway) to read
> and understand, and faster.  What am I missing?

In addition to the feature mentioned by Gunther in his reply to your
question (params' stickyness), it's about not clutterring your code with
HTML. Embedding HTML makes it harder to some degree to understand the Perl
code fast. Unless you are used to it :)

it's also about smart construction of HTML code using map() and similar
constructs:

  print table(-align => 'center',
              tr( map { td($_) } qw(foo bar) )
             );

or even more usual non-hardcoded use:

  print table(-align => 'center',
              tr( map { td($_),td($rows{$_} } keys %rows )
             );
now try to write the same code using HERE construct... you get the idea...

Anyway, I never use CGI::Q (function API), and always use OO interface,
which is faster in case of CGI.pm, since its API functions aren't true
functions and are resolved at run time. See the code and notes in the
guide if you need a proof.

Of course a better way to handle this is to use templates. TT is very
good, but we all wait for Perrin's talk at OSC which will summarize the
long thread we had here some 6 months ago and add his own experience.

_____________________________________________________________________
Stas Bekman              JAm_pH     --   Just Another mod_perl Hacker
http://stason.org/       mod_perl Guide  http://perl.apache.org/guide
mailto:[EMAIL PROTECTED]   http://apachetoday.com http://eXtropia.com/
http://singlesheaven.com http://perl.apache.org http://perlmonth.com/


Reply via email to