Re: CGI.pm and SSI
by Jouke (Curate) on Mar 12, 2001 at 20:00 UTC
|
As far as I can tell this is not possible. SSI are include-tags
in your HTML pages. These directives are processed by the webserver
at the time the server receives the request for that HTMLpage.
When a server gets a request for a script of some sort (Perl, Python, Shell, or whatever)
it executes this script. Period. There is no SSI in CGI-scripts.
All you can do with SSI however -and a very lot more- can be done in
Perl, so why do you want to use SSI in a Perlscript anyway?
Jouke Visser, Perl 'Adept'
| [reply] |
Re: CGI.pm and SSI
by Masem (Monsignor) on Mar 12, 2001 at 20:20 UTC
|
Three solutions:
Role your own SSI parser; namely, watch for the #include statements, and open up the file, and read it in, recursively following the #include links. This sorta works, and particularly if you mix static and dynamic pages.
Look at CGI::SSI. Haven't used it myself, but it should basically do the same as above.
Look into the Templating modules Text::Template, HTML::Template, and Template, all which easily support SSI-like features.
Dr. Michael K. Neylon - mneylon-pm@masemware.com
||
"You've left the lens cap of your mind on again, Pinky" - The Brain
| [reply] |
|
|
As for rolling your own parser you can look into HTML::TokeParser or HTML::Parser. They will save you from having to deal with the actuall parsing of tags.
Disclaimer: I haven't actually tried either of these with SSI tags so i dont if there are any pitfalls
| [reply] |
(tye)Re: CGI.pm and SSI
by tye (Sage) on Mar 12, 2001 at 21:08 UTC
|
Having recently been driven insane, I just have to comment that I think this is the single easiest-to-search-for topic I've run across in a long time and wonder why you didn't just type "CGI SSI" in the nice little "Search" box up there before posting?
-
tye
(but my friends call me "Tye")
| [reply] |
|
|
I typed in CGI::SSI and got a big goose-egg
-mjn
| [reply] |
|
|
Ah, but typing 'CGI SSI' (not 'CGI::SSI'), as tye suggested, does reveal a load of links.
Update: Is it fitting that my 150th post is a nitpick...? :-)
| [reply] |
Re: CGI.pm and SSI
by lhoward (Vicar) on Mar 12, 2001 at 20:05 UTC
|
This is not an answer to the question... but this question reminded me of
something I've been wondering for a while now?
Why aren't there client-side includes in the w3c standards (other than frames and iframes?)?
Seems to me like that would be a very useful feature that would
prevent lots of hacky, back-door programming... Something that would look like
an image tag, but would pull in text to an HTML document. like:
<txt src="http://example.com/cgi-bin/something">
discuss! | [reply] [d/l] |
|
|
This is supposed to be available in HTML4 via the OBJECT tag. However, nearly no browser supports OBJECT fully and properly for this to work well; in addition, unlike SSI which is put into the document before parsing, OBJECT would pull in the document during parsing and the 'environment' would not necessarily be carried over to it, thus making something things such as JavaScripts that span both document sets to fail (maybe not that bad of a thing, but still ....)
Dr. Michael K. Neylon - mneylon-pm@masemware.com
||
"You've left the lens cap of your mind on again, Pinky" - The Brain
| [reply] |
Re: CGI.pm and SSI
by stephen (Priest) on Mar 12, 2001 at 21:02 UTC
|
Check out Text::Vpp. It's a flexible preprocessor which handles include statements. That way, you can have statements like:
<P>And here is something from another file:
@INCLUDE other_file.txt
We now return to your regularly scheduled text.
</P>
That's assuming that you want to use a preformatted template file. Otherwise, a useful shortcut is to use File::Copy:
use File::Copy;
## ...
print STDOUT "<P>And here is something from another file:\n";
copy('other_file.txt', \*STDOUT) or print STDOUT "[Oops: $!]\n";
print STDOUT "We now return you to your regularly scheduled text.\n";
Theoretically, this might save some memory over reading the entire file into a string.
If you want to keep your HTML separate from your code (which is a worthy goal), then use one of the templating systems mentioned above.
stephen
| [reply] [d/l] [select] |
Re: CGI.pm and SSI
by jeorgen (Pilgrim) on Mar 13, 2001 at 01:26 UTC
|
mjn wrote:
(arguably this is impossible with my setup because .html files do not utilize mod_include on the server I am on, only .shtml files).
I assume your using Apache and cannot change in the httpd.conf file. This particular problem, with .html not being parsed by mod_include, can then usually be rectified like this:
Place an .htaccess file in your web root. Include the text: XBitHack on
Now, all .html-files that have the execution bit set will be server-parsed.
The execution bit can be set from the shell or usually from ftp (look for CHMOD command in e.g. cuteftp).
/jeorgen | [reply] [d/l] |