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);

Replies are listed 'Best First'.
Re: Tuning Embperl under mod_perl
by nite_man (Deacon) on May 22, 2003 at 11:37 UTC
    Well, I think nobody is interested to this post. Tell me, please, is this feature not good or does nobody work with Embperl and mod_perl?
          
    --------------------------------
    SV* sv_bless(SV* sv, HV* stash);