in reply to tt2 with perl cgi and a csv file

For what it's worth, I've done a couple of fairly large CGIs (a few thousand lines; almost all template code, which was in turn mostly XHTML, with a dispatch hash and related subs). You break your templates into blocks which can be named or put into vars like you've done above. Then stuff the Template code under __DATA__ and something like-

print CGI::header(); $template->process(\*DATA, $template_data) or warn $Template::ERROR;

Now that that's out there I'd recommend against it. It's okay for standalone, one-off stuff (in fact that's exactly what it's for because all the code is bundled in one file so it's easy to deploy and it's sometimes easier to edit code in one big file than 30 different ones). For stuff with room to grow it's an idea that will come back and bite.

It sounds like you're ready for CGI::Application, Catalyst, and friends. There is a learning curve but those sorts of packages abstract away *so* much many of the messy details (especially Catalyst) that you only realize how awesome it is after doing it manually yourself. Three weeks dedicated to reading docs and writing test code with Catalyst would likely shave at least that much time off a large project done with it.

Replies are listed 'Best First'.
Re^2: tt2 with perl cgi and a csv file
by Gokee2 (Acolyte) on Mar 27, 2008 at 20:04 UTC
    I looked at CGI::Application and Catalyst. I have rather been hoping to be all done inside of one or two weeks though. I guess I need to see a few more messy details before I am ready for them. This project should not get real big. I just need a way to edit the lines and a auto-create, to create a line for every new file dropped into archives, and that should be it. When it at last gets top heavy (like my own template system did before I started using tt2), I will look back into CGI::Application and Catalyst. Thanks!

      I'm all for it but let me regale you with a tale of my false economy.

      I did a standalone CGI, DB driven site for myself with really some of the tightest, nicest code I've ever written. It was entirely similar to a straightforward CGI::Application or Catalyst app, using URI dispatching and method checking and such. Because it was somewhere around the 1,000th CGI I'd written, it was easy, it was clean, and it took only 3 days to write because I could lean on experience + CPAN for sessions and DB stuff.

      Then I realized I wanted RSS/Atom on it. Well, there's another half day coding. Then comments. Another day or two gone and the code is now not looking so clean. I realized I'd like admin editing to work differently and have queues for drafts and published pages and be searchable and have topics/tags and Ajax and email updates and better error reporting and self-validate XHTML and... Holy crap, that is gonna be a drag... Redid it in Catalyst.

      Extra tasks like those when done in Catalyst can often be as short as 10 new lines of code. Easier to read. Easier to test. Easier to maintain. Fewer chances you left some exploit accidentally. Plus more jobs for Cat devs. :)

        Its odd having more then one place to reply on a thread. Thanks for telling me what AoH is stiller, I should have thought of that. Well I am thinking about going the Catalyst route. It seems like overkill but I thought that about tt2 before I started making my own little template system. Does catalyst work well with tt2? It looks rather... big. Also it seems to talk about SQLite. Does it also work with mysql? I have mysql on my server for doing mail routing. Also if I do go the Catalyst route should I move the system to a DB? Does it have a prebuilt thing that does about what I am trying to do? I started this project with a mind to do a quick convert of my old mailer address book manager so I have not really looked into what is already made for this kind of thing. Thanks!