You are viewing a plain text version of this content. The canonical link for it is here.
Posted to modperl@perl.apache.org by Neil Conway <nc...@klamath.dyndns.org> on 2001/05/19 05:28:06 UTC

Lightweight CGI.pm for PerlHandlers

Hi all,

I'd like to be able to use something similar to CGI.pm's HTML
generation methods in a PerlHandler I'm writing. Since I'm
not ever going to be using CGI directly (and also, the HTML
I'm doing is pretty simple), CGI.pm seems like overkill --
and from looking at some basic memory usage data, it seems
like you pay for this complexity/flexibility.

Is there a simple (fast, light) module that generates HTML
in a similar style to CGI.pm, for use with mod_perl?

At the moment, I'd rather not move to a system like
HTML::Mason or Template Toolkit -- the HTML I'm producing
is very simple (in fact, I've just been using $r->print
up to now, and it's not _too_ bad).

Thanks for any suggestions,

Neil


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 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/


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/



[OT] Lightweight CGI.pm - Why?

Posted by Larry Leszczynski <la...@furph.com>.
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: Lightweight CGI.pm for PerlHandlers

Posted by barries <ba...@slaysys.com>.
On Fri, May 18, 2001 at 11:28:06PM -0400, Neil Conway wrote:
> 
> Is there a simple (fast, light) module that generates HTML
> in a similar style to CGI.pm, for use with mod_perl?

You can check out HTML::EasyTags[1] and HTML::TagMaker[2]. They're all kinda
heavyweight, the first requires OO ($html->table(....)) either in the
API or inside of functional wrappers (IIRC), or passing of tags into and
out of wrapper functions, kinda like so:

   print table( 
       -align => "center",
       tr(
           td( "foo" ),
           td( "bar" ),
       ),
   ) ;

I think there's a need (or at last I haven't found a package) that
provides a simple, functional, non-nested (ie lightweight) set like so:

   print
       table( -align => "center" ),
 	   tr,
               td( "foo" ),
               td( "bar" ),
          _tr,
      _table ;

- Barrie

[1] http://search.cpan.org/doc/DUNCAND/HTML-EasyTags-1.05/EasyTags.pm
[2] http://search.cpan.org/doc/SKUD/CGI-FormMagick-0.4.0/lib/CGI/FormMagick/TagMaker.pm

Re: Lightweight CGI.pm for PerlHandlers

Posted by Peter Haworth <pm...@edison.ioppublishing.com>.
On Fri, 18 May 2001 23:28:06 -0400, Neil Conway wrote:
> I'd like to be able to use something similar to CGI.pm's HTML
> generation methods in a PerlHandler I'm writing. Since I'm
> not ever going to be using CGI directly (and also, the HTML
> I'm doing is pretty simple), CGI.pm seems like overkill --
> and from looking at some basic memory usage data, it seems
> like you pay for this complexity/flexibility.
> 
> Is there a simple (fast, light) module that generates HTML
> in a similar style to CGI.pm, for use with mod_perl?

If you just care about CGI.pm's "stickiness", my HTML::StickyForms module in combination with Apache::Request will generate form elements. You'll have to do the other elements yourself, though.


-- 
	Peter Haworth	pmh@edison.ioppublishing.com
"This seems dangerously close to COBOL,
 something difficult to argue in favor of."
		-- Tom Christiansen

Re: Lightweight CGI.pm for PerlHandlers

Posted by Bill Moseley <mo...@hank.org>.
At 11:28 PM 05/18/01 -0400, Neil Conway wrote:
>Is there a simple (fast, light) module that generates HTML
>in a similar style to CGI.pm, for use with mod_perl?

Well, not in the style similar to CGI.pm, but how about a here doc -- if
it's that simple.

>At the moment, I'd rather not move to a system like
>HTML::Mason or Template Toolkit -- the HTML I'm producing
>is very simple (in fact, I've just been using $r->print
>up to now, and it's not _too_ bad).

I bounce between HTML::Template, Template-Toolkit, and here docs.  Frankly,
mostly I use HTML::Templace for even really simple things (I use a here doc
for the template).

This kind of thing is personal style, but I think the templates make the
HTML stuff easier (and hidden away).

One of my New Years Resolutions was to do everything in Template-Toolkit so
I'd learn it better.  (But I'm also not drinking less beer, windsurfing
more, working less, or having more, eh, sleep, either.)


Bill Moseley
mailto:moseley@hank.org