I would like to suggest you one feature which can help to improve a performane if you use mod_perl and Embperl together.

Let us suppose that we have a library of HTML controls like this (it's just a shippet of library code):

[##################################################################### +#### # Begins a new form # Param#1: Form title (if undef or '' the no title is displaye +d) # Param#2: Name of the form # Param#3: Script to be called upon post request ###################################################################### +###] [* sub begin_form { ($title, $name, $script) = @_; captions_colwidth($capt_width); $form_name = $name; $valtext=''; if (defined($title) and ($title ne '')) { *] <TR> <TD vAlign="center" colspan=3> <table width="100%" cellPadding=0 border=0 cellSpacing=0><tr> + <td vAlign="center" align="left" width=7 bgcolor="#ffffff"> <img align="left" src="images/form_t_l.gif" border=0 hspa +ce=0 vspace=0></td> <td class="formTitle" vAlign="center" align="left" width="100% +"> <IMG title="[+ 'Form:' . $title +]" src="images/formlgnew.gif" border=0 vspace="0" hspace="1" align="absmi +ddle"> [+ $title +]</td> <td vAlign="center" align="right" bgcolor="#ffffff" width=22> <a href="javascript:history.go(-1)"> <img align="right" title="Previous Page" src="images/back-blue +_r.gif" border=0 hspace=0 vspace=0></a></td> <td vAlign="center" align="right" bgcolor="#ffffff" width=22> <a href="main.epl"> <img align="right" title="Main Page" src="images/home-blue_r. +gif" border=0 hspace=0 vspace=0></a></td> </tr> </table> </TD> </TR> [* } *] <form name="[+ $name +]" action="[+ $script +]" enctype="multipart/f +orm-data" method="post" onsubmit="return val_[+ $form_name +]()"> [* } *] [##################################################################### +### # Ends a form # Param#1: Number of pixel to live as empty space before clos +ing the # form(def=0) # Param#2: Number of pixel to live as empty space after closi +ng the # form(def=3) ##################################################################### +###] [* sub end_form { $height = shift; $lineh = defined($_[0]) ? shift : 3 ; *] </form> [* vspace($height); if ($lineh > 0) { *] <TR> <TD height="[+ $lineh +]"></TD> </TR> [* } } *] . . .
You can use it in your Embperl scripts in the following way:
[# Import all functions from the controls library into script #] [* Execute ({ inputfile => '_controls_lib.epl', import => 1 }) *] [# Call functions from the library #] [* begin_form('MyFormTitle', 'my_form_name', 'action_script_name'); textinput('Username', 'user', 140, 0, 'User Name'); password('Password', 'pass', 140, 0, 'User password'); form_buttons(); end_form(); *]

The problem lays, that every time, when your script will be called, this library will be loaded in the memory again. Of course, the bigger your library, the more server resourses will take for loading your script. I found the way to correct this.

You know that Apache using mod_perl caches all Perl modules which were called. We can use it.

Let's include the controls library into Perl module:

package LibControls; use Apache::Reload; use Embperl; use Exporter; use vars qw( @ISA @EXPORT_OK ); BEGIN { @ISA = qw ( Exporter ); Embperl::Execute({inputfile => $path_to_lib, import => 1, package +=>__PACKAGE__}); @EXPORT_OK = qw( begin_form textinput password ... end_form ); } 1;
and then we can use our library, which will be cached (if we want to reload this package we should just modify it or restart Apache), in our scripts:
[! use LibControls qw( begin_form, textinput, form_buttons, end_for +m ) !] [* begin_form('MyFormTitle', 'my_form_name', 'action_script_name'); textinput('Username', 'user', 140, 0, 'User Name'); form_buttons(); end_form(); *] <

This solution was very useful for my project and I hope that it will be useful for you.

P. S. If someone will be interested in full code of controls library I can public it.

      
--------------------------------
SV* sv_bless(SV* sv, HV* stash);

In reply to Tuning Embperl under mod_perl by nite_man

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.