You are viewing a plain text version of this content. The canonical link for it is here.
Posted to modperl@perl.apache.org by Larry Leszczynski <la...@furph.com> on 2001/05/20 00:18:20 UTC

[OT] Lightweight CGI.pm - Why?

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?


Thanks,
Larry Leszczynski
larryl@furph.com


Re: [OT] Lightweight CGI.pm - Why?

Posted by Tatsuhiko Miyagawa <mi...@edge.co.jp>.
Hi, 

On Sun, 20 May 2001 11:37:44 +0800
Gunther Birznieks <gu...@extropia.com> wrote:

> The reason I have used them in the past is that it is easier to do things 
> like widgets. TT and many pure template systems don't seem to have as much 
> of a widget concept when it comes to form variables.
> 
> It's nice to know that if you print a radio button form element using 
> CGI.pm, that if the value was set previously, CGI.pm knows how to print 
> which ones are checked and non checked and all that kind of crap.

HTML::FillInForm makes it possible while keeping code and design
apart! I use this in combination of HTML::Template. 



--
Tatsuhiko Miyagawa           Livin' On The EDGE, Co.,Ltd.
mailto:miyagawa@edge.co.jp         http://www.edge.co.jp/


Re: [OT] Lightweight CGI.pm - Why?

Posted by Ask Bjoern Hansen <as...@valueclick.com>.
On Sun, 20 May 2001, Stas Bekman wrote:

[...]
> it's also about smart construction of HTML code using map() and similar
> constructs:
> 
[...]
>
>   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...

eh, not really.

Without testing or really knowing what the CGI.pm functions does I
would think that it's approximately the same as:

print "<table>",map({"<tr><td>.$_.</td><td>.$rows{$_}</td></tr>\n" } keys %rows),"</table>";

Mixing HTML and code is ugly no matter how you do it.


For "automatic formhandling" I've very good experiences with
HTML::Embperl. It's magic is truly a blessing when you can use it.


 - ask

-- 
ask bjoern hansen, http://ask.netcetera.dk/   !try; do();
more than 100M impressions per day, http://valueclick.com


Re: [OT] Lightweight CGI.pm - Why?

Posted by Stas Bekman <st...@stason.org>.
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:stas@stason.org   http://apachetoday.com http://eXtropia.com/
http://singlesheaven.com http://perl.apache.org http://perlmonth.com/



Re: [OT] Lightweight CGI.pm - Why?

Posted by Gunther Birznieks <gu...@extropia.com>.
The reason I have used them in the past is that it is easier to do things 
like widgets. TT and many pure template systems don't seem to have as much 
of a widget concept when it comes to form variables.

It's nice to know that if you print a radio button form element using 
CGI.pm, that if the value was set previously, CGI.pm knows how to print 
which ones are checked and non checked and all that kind of crap.

At 06:18 PM 5/19/01 -0400, 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?
>
>
>Thanks,
>Larry Leszczynski
>larryl@furph.com

__________________________________________________
Gunther Birznieks (gunther.birznieks@eXtropia.com)
eXtropia - The Open Web Technology Company
http://www.eXtropia.com/