Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

Re: CGI.pm Disillusionment

by edoc (Chaplain)
on Jun 05, 2003 at 00:30 UTC ( #263200=note: print w/ replies, xml ) Need Help??


in reply to CGI.pm Disillusionment

hmm.. probably not what you want to hear, but here goes..

I don't actually understand why anyone would want to use the html generating tags in CGI.. never have, so I've never used it. 5 minutes with it this morning trying to solve a problem for another monk simply reminded me how uncomfortable I find it (they were already using it). I think I diagnosed the problem correctly and your post has just confirmed that for me.. You can't create the start of a table, then add the rows, then close off the table without doing it in one go.. that's just not right.. and definitely not modular.. all too hard for me.

templates, templates, templates.. that's the way to go as far as I'm concerned. Template::Toolkit Rocks! or maybe HTML::Template. Write your app to collect together all the data it needs to fill in the blanks in a template, then pass the data to the template module. In the template you can use whatever form of html you want and just insert variable tags, loops and things where you want the data put in.

Definitely worth the effort to get your head and app around this kinda thing.. IMHO..

cheers,

J


Comment on Re: CGI.pm Disillusionment
Re: Re: CGI.pm Disillusionment
by glwtta (Hermit) on Jun 05, 2003 at 04:28 UTC
    Just wanted to add my vote for templates.

    I don't think I've ever used the CGI.pm's HTML generation methods either, and I do find that Template::Toolkit indeed rocks.

    When talking about perl webapps, I usually also like to plug Class::DBI just because it plays so nicely with the Toolkit and makes form persistance a snap.

Re: Re: CGI.pm Disillusionment
by PodMaster (Abbot) on Jun 05, 2003 at 05:39 UTC
    You can't create the start of a table, then add the rows, then close off the table without doing it in one go.. that's just not right.. and definitely not modular.. all too hard for me.<
    That's simply not true.
    use CGI qw/ *table :standard /; print start_table({-border=>1}); print Tr( td( [qw, a s d f ,])); print end_table; __END__ <table border="1"><tr><td>a</td> <td>s</td> <td>d</td> <td>f</td></tr> +</table>


    MJD says you can't just make shit up and expect the computer to know what you mean, retardo!
    I run a Win32 PPM repository for perl 5.6x+5.8x. I take requests.
    ** The Third rule of perl club is a statement of fact: pod is sexy.

      Cool! ta!++ that solves b310's problem! 8)

      cheers,

      J

      Just to add to what the other monks have said on the subject, this is from the CGI.pm docs:

      There will be some times when you want to produce the start and end tags yourself. In this case, you can use the form start_tag_name and end_tag_name, as in:

      print start_h1,'Level 1 Header',end_h1;

      With a few exceptions (described below), start_tag_name and end_tag_name functions are not generated automatically when you use CGI. However, you can specify the tags you want to generate start/end functions for by putting an asterisk in front of their name, or, alternatively, requesting either "start_tag_name" or "end_tag_name" in the import list. Example:

      use CGI qw/:standard *table start_ul/;

      In this example, the following functions are generated in addition to the standard ones:

      start_table() (generates a <TABLE> tag) end_table() (generates a </TABLE> tag) start_ul() (generates a <UL> tag) end_ul() (generates a </UL> tag)

      I haven't tested it with every HTML tag, mind... ;-)

      Update: here's a link to the relevant part of the CGI.pm docs (as suggested by PodMaster).

Re: CGI.pm Disillusionment
by Coruscate (Sexton) on Jun 05, 2003 at 06:46 UTC

    Though I may agree about the ugliness of CGI's html generating subroutines, please have your facts straight. You can too start the table, add the content, then close it. I'll just take that as a misunderstanding on your part ;)

    #!/usr/bin/perl -w use strict; use CGI qw/:standard *table/; print header(), start_html('foo bar qux'), start_table(); print Tr( td('foo'), td('bar'), td('qux') ); print end_table(), end_html();


    If the above content is missing any vital points or you feel that any of the information is misleading, incorrect or irrelevant, please feel free to downvote the post. At the same time, please reply to this node or /msg me to inform me as to what is wrong with the post, so that I may update the node to the best of my ability.

Re: Re: CGI.pm Disillusionment
by Dog and Pony (Priest) on Jun 05, 2003 at 20:56 UTC
    When I used to write web stuff, I frequently used CGI.pm's HTML-generators while prototyping my code. Since I used CGI.pm anyways, I could whip up something that looked butt ugly but worked really fast, as proof of concept or as a starting point. Then, when the basic functionality was there, I'd create (or get from a designer) a HTML template and used HTML::Template instead.

    I've heard lots of good about TT as well, but haven't used it myself. I like HTML::Template because it only does a few things, does it well and fast, and that helps keeping the logic in the code as much as possible.

    I sincerely agree that one should not use CGI.pm to generate the HTML for anything "real" though. That is still mixing markup and code in a bad way, though for some small things, a foreach around some $q->li's are definitely a fast way to get the job done. YAGNI sometimes applies to templates as well. :)


    You have moved into a dark place.
    It is pitch black. You are likely to be eaten by a grue.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://263200]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others having an uproarious good time at the Monastery: (10)
As of 2014-08-20 18:36 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The best computer themed movie is:











    Results (121 votes), past polls