Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

Re: Clarifications in subroutines, CGI.pm, HTML::Template and performance

by Asim (Hermit)
on Jun 18, 2006 at 09:54 UTC ( [id://556070]=note: print w/replies, xml ) Need Help??


in reply to Clarifications in subroutines, CGI.pm, HTML::Template and performance

Is it fair to say that if I use HTML::Template, my scripts would be organized better than just using CGI.pm? Again, is there any impact on the performance in terms of using HTML::Template rather than CGI.pm alone?

As a GENERAL rule, yes, your code is improved by taking "display-only" aspects out of the Perl code proper. Much like modules, it makes the code easier to follow and read, and thus debug. By keeping your HTML as mostly-pure HTML, it also makes it easier to debug and validate it, as well.

In terms of speed, switching to HTML::Template will make a mark. There are ways around that; Template Toolkit (sort of HTML::Template's big brother) will compile it's templates for added speed, and I suspect H::T has similar capacity. And indeed, a quick search on Google shows HTML::Template::Compiled and HTML::Template::JIT. Another cheap/easy way to help with CGI apps (this one more memory than speed) is to, when you're running with templating full-time, use a smaller version of the CGI module, like CGI::Simple, which takes out the HTML-generating portions of the full-bore CGI, leaving the bits that are for parameter-processing and header-generating.

I have a tendency to create separate cgi scripts for each task. i.e., I call separate scripts to check login, execute commands, read and display menus, etc.. etc.. Should I minimize the no of cgi programs

Frankly, with CGI, I worry far more about readability and maintaining of code. You pay such a cost in basic CGI overhead that shaving time for your CGI code is almost not worth it in many cases; if you want to optimize, do it after you convert to a mod_perl or similar setup, if you need to. However, staying with CGI-based solutions, I'd recommend you look into CGI::Application, which is a nice module for running multiple CGI "scripts" under one umbrella. If you're willing to make a bigger leap; I think you'll find a web framework like Catalyst to be a powerful ally; it has authorization routines as an easy-to-use module, for example.

How easy (or difficult) it is to move to mod_perl or any other better technology?

The more you code in a nice, easy-to-debug style, the better off you are with mod_perl. You might want to start with Apache::PerlRun, using the CGI conversion guide on the mod_perl site to sort out how to make this happen. Some of this will depend on if you're using mod_perl version 1 or 2, of course.

If mod_perl is not your speed, there are other solutions, such as FastCGI.

I hope this helps.

----Asim, known to some as Woodrow.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others learning in the Monastery: (3)
As of 2024-03-28 17:52 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found