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

If I use an SSI include virtual="../mod_perl_turned_on_here/foo.pl" or the similar within an (S)HTML file, will the benefits of mod_perl still be present? The idea is to build a system primarily embedded into HTML files (as opposed to running the whole thing from perl and being forced to mod_perl) with the ability to switch to mod_perl if the load gets too heavy.

Thanks
  • Comment on Does mod_perl work when used as an include?

Replies are listed 'Best First'.
Re: Does mod_perl work when used as an include?
by valdez (Monsignor) on Sep 01, 2002 at 11:49 UTC

    May I disagree with you, tadman? You even suggest to use PHP ;-)

    I think that components can be very powerful; the Eagle Book describes an interesting approach to SSI, that uses most of the peculiarities of mod_perl. Apache::SSI is another solution, that can be also extended.

    Hope this helps. Ciao, Valerio

    Update: the answer to your question is yes, it works under mod_perl.

Re: Does mod_perl work when used as an include?
by tadman (Prior) on Sep 01, 2002 at 10:06 UTC
    Can SSI just die, please? They're awful. They're older than CGI, if you can imagine that.

    If you're pressed for time, you can use here documents with limited string interpolation. If you're dealing with non-technical types, you can use a simple templating system such as Text::Template. Or, if you're in the middle, you could consider using something like PHP, though that is really a last resort.

    What I would do is try and develop a system that can do these insertions for you without the overhead of SSI. It's not terribly difficult. Apache::Filter can be handy for this kind of work, as it feeds you the file that is being processed, and you can modify it accordingly before sending it to the browser.

    I know this sounds bitter and cynical, but a mod_perl handler is so easy to write if you have the right reference. Writing Apache Modules in Perl and C is one such book. All you have to do, in the end, is write a suitable handler function, which at it's most basic is this:
    package MyHandler; use Apache::Constants qw[ :standard ]; sub handler { my ($r) = @_; # Apache Request Object do_some_stuff(); # Your function(s) print "Some stuff\n"; # Your output return OK; }
    What you do in there is entirely up to you. In some cases, it's even easier than CGI. There are examples in the book for inserting a header/footer combination on a directory of HTML files. These can be adapted to do things such as insert a bit of text on a tag.

    Since it's all Perl, you can link in any code you need to your handler and let it rip from there. As you'd expect, it can be pretty fast.
Re: Does mod_perl work when used as an include?
by PodMaster (Abbot) on Sep 01, 2002 at 09:51 UTC