NAME

CGI::SSI - Use SSI from CGI scripts

SYNOPSIS

# autotie STDOUT or any other open filehandle

use CGI::SSI (autotie => 'STDOUT');

print $shtml; # browser sees resulting HTML

# or tie it yourself to any filehandle.

use CGI::SSI;

open(FILE,"$html_file")    or die $!;
my $ssi = tie(*FILE,'CGI::SSI', filehandle => 'FILE')
        or die 'no tie';
print FILE $shtml; # HTML arrives in the file

# or use the Object-Oriented interface:

my $ssi = CGI::SSI->new();

$ssi->if($expr);
    $html .= $ssi->process($shtml);
$ssi->else();
    $html .= $ssi->process($shtml2);
$ssi->endif();

print $ssi->include($type, $path);
print $ssi->flastmod($filename);

# or roll your own favorite flavor of SSI:

package CGI::SSI::MySSI;
use CGI::SSI;
@CGI::SSI::MySSI::ISA = qw(CGI::SSI);

sub include {
    my($self,$type,$arg) = @_; # $type is 'file' or 'virtual'
    # my idea of include goes something like this...
    return $html;
}
1;

DESCRIPTION

CGI::SSI has it's own flavor of SSI. Test expressions are Perlish. You may create and use multiple CGI::SSI objects. They will not step on each other's variables.

You can either tie (or autotie) a filehandle, or use the following interface methods. When STDOUT is tied, printing shtml will result in the browser seeing the result of ssi processing.

If you are going to tie a filehandle manually, you need to pass the name of the filehandle to CGI::SSI like so:

tie(*FH,'CGI::SSI', filehandle => 'FH');

$ssi = CGI::SSI->new()

Creates a new CGI::SSI object.

$ssi->config($type, $argument)

$type is either 'errmsg','timefmt', or 'sizefmt'. Valid values for $argument depend on $type:

errmsg - Any string. Defaults to '[an error occurred while processing this directive]'.

timefmt - A valid first argument to Date::Format::strftime(). Defaults to 'scalar localtime()'.

sizefmt - 'bytes' or 'abbrev'. Default is 'abbrev'.

$ssi->echo($varname)

Returns the value of $varname.

$ssi->exec($type, $resource)

$type may be 'cmd' or 'cgi'. $resource is either an absolute or relative filename.

$ssi->flastmod($type, $resource)

$type is either 'file' or 'virtual'. $resource is either a relative or absolute filename.

$ssi->fsize($type, $resource)

Arguments are identical to those of flastmod().

$ssi->include($type, $resource)

Arguments are identical to those of exec().

$ssi->printenv()

Returns a listing of the environment variable names and their values.

$ssi->set($varname, $value)

Associate a value with a variable.

FLOW CONTROL METHODS

The following methods may be used for flow-control. During a `block' where the test $expr was false, nothing will be returned (or printed, if tied).

$ssi->if($expr)

If $expr is excluded, it's considered to be false.

$ssi->elif($expr)

If $expr is excluded, it's considered to be false.

$ssi->else()
$ssi->endif()

SEE ALSO

Apache::SSI and the SSI 'spec' at: http://www.apache.org/docs/mod/mod_include.html

COPYRIGHT

Copyright 1999 James Tolley All Rights Reserved.

This is free software. You may copy and/or modify it under the same terms as perl itself.

AUTHOR

James Tolley <james@jamestolley.com>