On Thu, Jan 31, 2002 at 02:32:50PM -0500, Joshua Spoerri wrote: > a really basic mod_perl usage question: > what's the preferred way for multiple embperl pages to include a single > instance of data from one file (including apache::dbi handles behind > dbix objects ) ? > > i'd like to do: > [- > Execute({inputfile=>'mycommon.html', package=>'mycommon'}); > $mycommon::myset->Search(); > -] > and have mycommon.html consist of one large [! !] block > > if i instead do the Execute in startup.pl (which would be even better, > since it could be shared by all apache children), my pages don't even > see the package.
You can use PerlSetEnv EMBPERL_OBJECT_HANDLER_CLASS Some::Module .. which will cause all $req objects to inherit from this class. This class must contain HTML::Embperl::Req in his @ISA array This is good if you just have one unchanging module. If you have multiple or, like me, you want them to be different for different parts of the site then: use the 'object' option to Execute like so: $lib = Execute({object => 'lib.epl'}); This has several advantages: 1) lib.epl can be overridden in different sections of your site. For example, you've got a function that returns a list of icons/links to place in a menubar. Very easy to override this function whenever you need a change in a different directory like so: /somedir/lib.epl: [# This makes embperl look through the search path for another lib.epl to inherit from. Isn't restricted to be one directory back! lib.epl can be found anywhere further in the search path. #] [! Execute ({isa => '../lib.epl'}) !] [! sub menu_content { my $self = shift; # add something to the bottom return ( $self->SUPER::menu_content(), 'something' ); } !] 2) You can stick the $lib object into $req in your base.epl or init.epl or whatever like so: base.epl: $req = shift; $req->{libobj} = Execute({object => 'lib.epl'}); somepage.html: $req = shift; # call the do_stuff() function in lib.epl $req->{libobj}->do_stuff( @my_args ); 3) You're not limited to just one. Have as many as you like. A veritable object party! Hope this helps. -- Andrew O'Brien Senior Engineer email: [EMAIL PROTECTED] Switch Online Group Pty Limited phone: +61 2 9299 1133 ABN 89 092 286 327 fax: +61 2 9299 1134 --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]