For Programmers: Free Programming Magazines  


Home > Archive > PERL CGI Beginners > September 2005 > Re: Help w/Modules









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Re: Help w/Modules
Bill Stephenson

2005-09-25, 7:55 am

On Sep 24, 2005, at 10:59 AM, Bill Stephenson wrote:

> I'm trying to understand how to convert my CGI scripts to use modules.


I worked this problem out. Reading the docs and this page
(http://www.perl.com/pub/a/2001/06/05/cgi.html) for CGI::Application
has helped me better understand how to use modules, but I'm still left
somewhat on the subject of efficient web application design.

My original question had to do with "How big is too big" and I don't
see the advantage of creating a large module accessed by a small
"Instance" script, as compared to a a single, large, cgi script that
uses sub-routines, to process "run-modes". What happens when your
module or script grow to over 1 megabyte?

Wouldn't it be more efficient for the server to run a small script that
contains only the set-up and sub-routines needed to process a single
"run-mode" instead of loading all the data needed to process all the
"run-modes" used in an entire application?

Also, the above article implies that web applications created with
CGI::Application are ready for mod_perl. I've never tried creating a
script that would run with mod_perl but if this is true, I'd like to
try it out. Any feedback on using CGI::Application would also be much
appreciated.

Kindest Regards,
--
Bill Stephenson

Randal L. Schwartz

2005-09-25, 6:55 pm

>>>>> "Bill" == Bill Stephenson <bills@perlhelp.com> writes:

Bill> Wouldn't it be more efficient for the server to run a small script
Bill> that contains only the set-up and sub-routines needed to process a
Bill> single "run-mode" instead of loading all the data needed to process
Bill> all the "run-modes" used in an entire application?

That's why I created CGI::Prototype::Hidden... to lazy-load the code
for the particular step of the application.

--
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
<merlyn@stonehenge.com> <URL:http://www.stonehenge.com/merlyn/>
Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.
See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training!
Bill Stephenson

2005-09-27, 7:55 am

On Sep 25, 2005, at 2:01 PM, Randal L. Schwartz wrote:

> That's why I created CGI::Prototype::Hidden... to lazy-load the code
> for the particular step of the application.


Randal, this really piqued my interest and after a little poking around
I found this link;

http://www.stonehenge.com/merlyn/LinuxMag/

and read these articles;

Introduction to CGI::Prototype (part 1) (May 05)
Introduction to CGI::Prototype (part 2) (Jun 05)
Introduction to CGI::Prototype (part 3) (Jul 05)

and what you're doing here started to sink in a bit. The way
"lazy-load" works is still magic to me, but it seems to perfectly
answer the problem I was worried about. But I learned more than that
and I just love the logic used here...

"The state is used to select a particular class for the controller,
along with the default template for that class. Once a state has been
selected, the corresponding class is loaded into the program (unless
already defined), and used to determine the next step in the program.
This ``lazy loading'' behavior permits a minimum of loading for CGI
programs: at most, two different state-named classes are loaded per web
hit."

I read this right after a few hours of playing with an easier way to
get the name of template I wanted after a user submits a form. I came
up with a solution that I thought worked pretty good, then I realize
that you've done away with the problem altogether. I can use this logic
in any cgi application I make, it's so simple and makes such good
sense.

I'll read the above articles a few more times and then create a small
app with CGI::Prototype in a day or two. I'm pretty slow at absorbing
this stuff but I must thank you for helping me better understand where
I need to go and how to get there with my cgi applications.

BTW, how's the "Cookbook" coming?

Kindest Regards,
--
Bill Stephenson

Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com