Steny has asked for the wisdom of the Perl Monks concerning the following question:

I'm trying to decide what the easiest (and most realistic) way to design my stie would be.

All of my pages have a top area that is always the same, a left menu that is always the same, and then a right menu that changes depending on whether or not the user is logged in (and the way that it changes is unique to every user, so part of the right frame must be generated by a PERL script on every execution). The contents of the page being displayed is in the middle of the page. I'm not using frames, just tables to split the page all up so that it kind of appears that way.

I was going to use SSI and just include the portions of pages that need to be generated by script, but have come to the conclusion that it MIGHT be better to just make all pages PERL generated using HTML::Template, instead of only those absolutely necessary.

If I use a .shtml file to create a page, I theoretically would need to do...
!--#include virtual="/cgi-bin/top.cgi"--

.... page content .... OR !--#include virtual="/cgi-bin/scriptToCreatePageContent.cgi"--

!--#include virtual="/cgi-bin/bottom.cgi"--

top.cgi basically just creates a HTML::Template and displays it. bottom.cgi would create the user-unique menus, and display them via HTML::Template as well.

What I've figured is that if I do this method, every time a page is called, the page is loaded, but 2-3 CGI scripts are executed as well. If I create all of my pages using a PERL script, I could do all the executions within 1 script (but would need to use either "require" or "do" so that I could pull subroutines for another script to generate the top and bottom, in case I wanted to modify the top or bottom without having to edit every single page/script.

Basically, I want to make sure that my site is relatively efficient, so that my host doesn't contact me down the road, and tell me that I'm bogging down their server & need to recode everything.

All the Perl scripts are pretty simple for these pages. One does a quick loop for something, before spitting out an HTML::Template, the other just prints out an HTML::Template... with only a little different based on whether or not the user is logged in.

My questions:
1) If I get several thousand visitors a day browsing through my site (say for a total of 20,000 impressions per day), am I risking that these scripts be too demanding on a shared hosting server that my host contacts me to recode them? I don't think that such simple scripts would be very demanding, but at the same time... a large quantity of impressions may be a different story.

2) What's the different between 'require' and 'do'? It seems like they basically do the same time, or at least can... for what I need them to (which is including subroutines defined in another file into a script). From a performance standpoint, is there much of a difference?

Any feedback/help would be greatly appreciated guys.

Just learnin' as I go, and trying to learn it right.. the first time.

Thanks Monks!


Steny

Replies are listed 'Best First'.
just OO HTML::Template would do
by chanio (Priest) on Jun 24, 2004 at 01:35 UTC
    You should understand first, what you know by now:
    • HTML::Template returns just some text, right?
    • And that text could fit inside one of any other H-T field, ok?
    So, instead of using use or require, just study how you could 'inherit' classes that hold H-Ts in it. Every class should handle one level or directory of your page (sort of). When you want to go deeper in some level, you call another class that inherits all the other values and returns the text to put inside an H-T field from the upper level.

    I am also planning to manage a site by this way.

    .{\('v')/}
    _`(___)' __________________________
Re: 'require' vs. 'do' vs. SSI include
by saskaqueer (Friar) on Jun 24, 2004 at 05:25 UTC

    I will put the suggestion out there that you could install The Template Toolkit along with the Template CPAN module. Especially with a mod_perl environment, this creates a very simple yet efficient tool. Your template for a content page could turn out to look something like the following:

    [% INCLUDE html_header.tmpl pagetitle="Sample Page" %] <p> This is the content for this page. </p> [% INCLUDE html_footer.tmpl %]
Re: 'require' vs. 'do' vs. SSI include
by ctilmes (Vicar) on Jun 24, 2004 at 00:44 UTC
    Any feedback/help would be greatly appreciated guys.

    Those are reasonable options. I use Mason for this sort of thing. You might check it out as another option to consider.

Re: 'require' vs. 'do' vs. SSI include
by kiat (Vicar) on Jun 24, 2004 at 03:03 UTC
    Hi Steny,

    I'm doing something similar to what you've described - mixing of static and dynamic contents on a page. I suspect it's a fairly common practice.

    I'm not so certain about the merits of using 'includes' in your .shtml file. What I do know is that such a strategy would probably require the use of different scripts to produce the desired outputs. One disadvantage of this approach is having to maintain these little scripts.

    Since you mentioned HTML::Template, which is what I'm using, why not have a template file that already has all the static contents (top and bottom) and make use of some display logic (tmpl_if, tmpl_else, tmpl_include, etc) to include the dynamic content? You need only to tweak one template file if any of the static contents needs to be modified. If you want to modify the dynamic content (include more things or exclude existing items), just tweak the script.

    There might be other more efficient ways but using an 'intelligent' template that consists of part static and part dynamic content is one possible solution.

    cheers,

Re: 'require' vs. 'do' vs. SSI include
by perrin (Chancellor) on Jun 24, 2004 at 15:04 UTC
    When running under mod_perl, multiple calls through SSI are very efficient. When using CGI, they are not. So, if you have to stick with CGI, use the "everything from one Perl script" approach. If you can use mod_perl, the SSI approach would be my first choice, although either way can work.
      Thx to everyone for their feedback. It's been greatly appreciated.

      I'm going to go with CGI-driven for everything. The dynamic content is VERY dynamic (changes all the time, depending on several factors... and can vary immensely between users), so having a template file do all the deciding on what is and isn't displayed would probably be inneficient, and mind numbing to code & keep updated.

      Now just to figure out how to get index.cgi as my default file rather then index.shtml
      :-)

      Thx again guys!

      Steny