CGI-SSI
view release on metacpan or search on metacpan
0.92 Wed Jul 08 2007
- newlines OK in SSI directives
0.91 Mon May 28 2007
- fixed bad LWP::UserAgent arg
- added documentation to make the scope of SSI variables more clear.
- timefmt applied to LAST_MODIFIED
0.90 Tue Apr 24 2007
- fixed bad HTTP::Cookies arg
0.89 Fri Apr 20 2007
- nested if errors fixed (with thanks to Colin Fine)
0.88 Fri Sept 2 2005
- warn on errors
- https URIs
0.87 Fri Sept 2 2005
- CLOSE
# http://module-build.sourceforge.net/META-spec.html
#XXXXXXX This is a prototype!!! It will change in the future!!! XXXXX#
name: CGI-SSI
version: 0.92
version_from: SSI.pm
installdirs: site
requires:
Date::Format: 0
File::Spec: 0
HTML::SimpleParse: 0
HTTP::Cookies: 0
HTTP::Response: 0
LWP::UserAgent: 0
URI: 0
distribution_type: module
generated_by: ExtUtils::MakeMaker version 6.17
Makefile.PL view on Meta::CPAN
# See lib/ExtUtils/MakeMaker.pm for details of how to influence
# the contents of the Makefile that is written.
WriteMakefile(
'NAME' => 'CGI::SSI',
'VERSION_FROM' => 'SSI.pm', # finds $VERSION
'PREREQ_PM' => {
HTML::SimpleParse => 0,
File::Spec => 0,
LWP::UserAgent => 0,
HTTP::Response => 0,
HTTP::Cookies => 0,
URI => 0,
Date::Format => 0,
},
);
Creates a new CGI::SSI object. The following are valid (optional)
arguments:
DOCUMENT_URI => $doc_uri,
DOCUMENT_NAME => $doc_name,
DOCUMENT_ROOT => $doc_root,
errmsg => $oops,
sizefmt => ('bytes' || 'abbrev'),
timefmt => $time_fmt,
MAX_RECURSIONS => $default_100, # when to stop infinite loops w/ error msg
COOKIE_JAR => HTTP::Cookies->new,
$ssi->config($type, $arg)
$type is either 'sizefmt', 'timefmt', or 'errmsg'. $arg is similar
to those of the SSI "spec", referenced below.
$ssi->set($varname => $value)
Sets variables internal to the CGI::SSI object. (Not to be confused
with the normal variables your script uses!) These variables may be
used in test expressions, and retreived using $ssi->echo($varname).
These variables also will not be available in external, included
$ssi->flastmod($type, $filename)
Similar to "include".
$ssi->fsize($type, $filename)
Same as "flastmod".
$ssi->printenv
Returns the environment similar to Apache's mod_include.
$ssi->cookie_jar([$jar])
Returns the currently-used HTTP::Cookies object. You may optionally
pass in a new HTTP::Cookies object. The jar is used for web requests
in exec cgi and include virtual directives.
FLOW-CONTROL METHODS
The following methods may be used to test expressions. During a "block"
where the test $expr is false, nothing will be returned (or printed, if
tied).
$ssi->if($expr)
The expr can be anything Perl, but care should be taken. This causes
problems:
package CGI::SSI;
use strict;
use HTML::SimpleParse;
use File::Spec::Functions; # catfile()
use FindBin;
use LWP::UserAgent;
use HTTP::Response;
use HTTP::Cookies;
use URI;
use Date::Format;
our $VERSION = '0.92';
our $DEBUG = 0;
sub import {
my($class,%args) = @_;
return unless exists $args{'autotie'};
$self->{'_config'} = {
errmsg => ($args{'errmsg'} || '[an error occurred while processing this directive]'),
sizefmt => ($args{'sizefmt'} || 'abbrev'),
timefmt => ($args{'timefmt'} || undef),
};
$self->{_max_recursions} = $args{MAX_RECURSIONS} || 100; # no "infinite" loops
$self->{_recursions} = {};
$self->{_cookie_jar} = $args{COOKIE_JAR} || HTTP::Cookies->new();
$self->{'_in_if'} = 0;
$self->{'_suspend'} = [0];
$self->{'_seen_true'} = [1];
return $self;
}
sub TIEHANDLE {
my($class,%args) = @_;
Creates a new CGI::SSI object. The following are valid (optional) arguments:
DOCUMENT_URI => $doc_uri,
DOCUMENT_NAME => $doc_name,
DOCUMENT_ROOT => $doc_root,
errmsg => $oops,
sizefmt => ('bytes' || 'abbrev'),
timefmt => $time_fmt,
MAX_RECURSIONS => $default_100, # when to stop infinite loops w/ error msg
COOKIE_JAR => HTTP::Cookies->new,
=item $ssi->config($type, $arg)
$type is either 'sizefmt', 'timefmt', or 'errmsg'. $arg is similar to
those of the SSI C<spec>, referenced below.
=item $ssi->set($varname => $value)
Sets variables internal to the CGI::SSI object. (Not to be confused
with the normal variables your script uses!) These variables may be used
=item $ssi->fsize($type, $filename)
Same as C<flastmod>.
=item $ssi->printenv
Returns the environment similar to Apache's mod_include.
=item $ssi->cookie_jar([$jar])
Returns the currently-used HTTP::Cookies object. You may optionally
pass in a new HTTP::Cookies object. The jar is used for web requests
in exec cgi and include virtual directives.
=back
=head2 FLOW-CONTROL METHODS
The following methods may be used to test expressions. During a C<block>
where the test $expr is false, nothing will be returned (or printed,
if tied).
# config
{
my %months = map { ($_,1) } qw(January February March April May June
July August September October November December);
# create a tmp file for testing.
use IO::File;
use POSIX qw(tmpnam);
my($filename,$fh); # Thanks, Perl Cookbook!
do { $filename = tmpnam() } until $fh = IO::File->new($filename, O_RDWR|O_CREAT|O_EXCL);
# select( ( select($fh), $| = 1 )[0] );
print $fh ' ' x 10;
close $fh;
my $ssi = CGI::SSI->new();
$ssi->config(timefmt => "%B");
ok($months{ $ssi->flastmod(file => $filename) },'config 1');
$ssi->config(sizefmt => "bytes"); # TODO: combine these calls to config.
, "recursion check");
# re-open STDERR and continue
open STDERR,">©" or die "no reassign to STDERR: $!";
}
# test cookie support
SKIP: {
eval "use HTTP::Cookies; 1" or skip("HTTP::Cookies not installed", 1);
my $jar = HTTP::Cookies->new({});
$jar->set_cookie(1,'mycookie','COOKIEVAL','/','www.bitperfect.com',80,0,0,100);
my $ssi = CGI::SSI->new(COOKIE_JAR => $jar);
my $html = $ssi->process(qq[<!--#include virtual="http://www.bitperfect.com/cgi-bin/cgi-ssi/cookietest.cgi"-->]);
ok($html =~ m'COOKIEVAL', "cookie support");
}
SKIP: {
# tie by hand & close
my($dir) = tempdir();
( run in 1.747 second using v1.01-cache-2.11-cpan-e9199f4ba4c )