CGI-Template
view release on metacpan or search on metacpan
lib/CGI/Template.pm view on Meta::CPAN
package CGI::Template;
use 5.012004;
use strict;
use warnings;
use Carp;
require Exporter;
use vars qw(
$VERSION $FORM_CHECK @ISA @EXPORT @EXPORT_OK $DOCTYPE $STRICT
$TRANSITIONAL $FRAMESET $HTML5
);
our @ISA = qw(Exporter);
# Items to export into callers namespace by default. Note: do not export
# names by default without a very good reason. Use EXPORT_OK instead.
# Do not simply export all your public functions/methods/constants.
# This allows declaration use CGI::Template ':all';
# If you do not need this, moving things directly into @EXPORT or @EXPORT_OK
# will save memory.
our %EXPORT_TAGS = ( 'all' => [ qw(
) ] );
our @EXPORT_OK = ( @{ $EXPORT_TAGS{'all'} } );
our @EXPORT = qw();
our $VERSION = '0.01';
# These variables just define standard HTML DOCTYPEs. We'll use them throughout.
$STRICT = qq{<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"\n"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">\n\n};
$TRANSITIONAL = qq{<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"\n"http://www.w3.org/TR/html4/loose.dtd">\n\n};
$FRAMESET = qq{<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Frameset//EN"\n"http://www.w3.org/TR/html4/frameset.dtd">\n\n};
$HTML5 = qq{<!DOCTYPE html>};
# Use HTML5 by default.
$DOCTYPE = $HTML5;
#
#
#
sub new {
my $class = shift;
my %passed_hash = @_;
my $doctype = $passed_hash{doctype};
my $request_method = $passed_hash{request};
my $template_dir = $passed_hash{templates};
$template_dir = "templates" unless $template_dir;
my $crm = $ENV{'REQUEST_METHOD'};
if( $request_method ){
if( $request_method =~ /^get$/i ){
unless( $crm =~ /^get$/i ){
&error("Incorrect request method");
}
} elsif( $request_method =~ /^post$/i ){
unless( $crm =~ /^post$/i ){
&error("Incorrect request method");
}
} else {
croak "CGI::Template : Invalid request argument passed to new(): $request_method";
}
}
$doctype = "" unless $doctype;
if( $doctype =~ /^transitional$/i || $doctype =~ /^loose$/i ){
$DOCTYPE = $TRANSITIONAL;
} elsif( $doctype =~ /^frameset$/i ){
$DOCTYPE = $FRAMESET;
} elsif( $doctype =~ /^strict$/i ){
$DOCTYPE = $STRICT;
} elsif( $doctype =~ /^html5$/i ){
$DOCTYPE = $HTML5;
} elsif( $doctype =~ /^none$/i ){
$DOCTYPE = "";
( run in 1.237 second using v1.01-cache-2.11-cpan-600a1bdf6e4 )