ZM::SSI - SSI parser for CGI


ZM-SSI documentation Contained in the ZM-SSI distribution.

Index


Code Index:

NAME

Top

ZM::SSI - SSI parser for CGI

VERSION

Top

SSI.pm v 0.0.5

DESCRIPTION

Top

Parsing SSI from Perl script. Understand: <!--#include file="..." --> <!--#exec cgi="..." -->

METHODS

Top

The following public methods are availible:

ZM::SSI::parse($string);

Parsing string with HTML code.

COPYRIGHT

Top

AUTHOR

Top

Zet Maximum ltd. http://www.zmaximum.ru/


ZM-SSI documentation Contained in the ZM-SSI distribution.

package ZM::SSI;
$ZM::SSI::VERSION = '0.0.5';
use strict;

sub parse
{
	my $data = shift;
	$data=~s/<!--#include file\s*=\s*"(\S+)"\s*-->/${\(include($1))}/gi;
	$data=~s/<!--#exec cgi\s*=\s*"(\S+)"\s*-->/${\(execcgi($1))}/gi;
	return($data);
}

sub include
{
	my $file=shift;
	$file=$ENV{DOCUMENT_ROOT}.$file if($file=~/^\//);
	my $old;
	$old=$/;
	undef($/);
	open(DATAFOR,$file);
	my $data=<DATAFOR>;
	close(DATAFOR);
	$/=$old;
	$data=parse($data);
	return($data);
}

sub execcgi
{
	my $file=shift;
	if($file=~/^([^?]*)\?(.*)/) # Cut Query string
	{
		$file=$1;
		if($ENV{QUERY_STRING} eq '')
		{
			$ENV{QUERY_STRING}=$2;
		}
		else
		{
			$ENV{QUERY_STRING}.='&'.$2;
		}
	}
	if($file=~/^\//)
    {
        $file=$ENV{DOCUMENT_ROOT}.$file;
    }
    else
    {
		$file="./$file";
    }
	my $data=`$file`;
	$data=~s/^.*\n\n//;
	$data=parse($data);
	return($data);
}
#############################

1;

__END__