CGI-Simple
view release on metacpan or search on metacpan
lib/CGI/Simple.pm view on Meta::CPAN
}
$type = $type || 'text/html';
my @header = ( "Content-Type: $type" );
push @header, @other;
my $CRLF = $self->crlf; # get CRLF sequence
return ( join $CRLF, @header ) . $CRLF . $CRLF;
}
sub multipart_end { return $_[0]->{'.separator'} }
sub multipart_final { return $_[0]->{'.final_separator'} }
################# Debugging Methods ################
sub read_from_cmdline {
my @words;
if ( $_[0]->{'.globals'}->{'DEBUG'} == 1 and @ARGV ) {
@words = @ARGV;
}
elsif ( $_[0]->{'.globals'}->{'DEBUG'} == 2 ) {
require "shellwords.pl";
print "(offline mode: enter name=value pairs on standard input)\n";
chomp( my @lines = <STDIN> );
@words = &shellwords( join " ", @lines );
}
else {
return '';
}
@words = map { s/\\=/%3D/g; s/\\&/%26/g; $_ } @words;
return "@words" =~ m/=/ ? join '&', @words : join '+', @words;
}
sub Dump {
require Data::Dumper; # short and sweet way of doing it
( my $dump = Data::Dumper::Dumper( @_ ) )
=~ tr/\000/0/; # remove null bytes cgi-lib.pl
return '<pre>' . escapeHTML( 1, $dump ) . '</pre>';
}
sub as_string { Dump( @_ ) } # CGI.pm alias for Dump()
sub cgi_error {
my ( $self, $err ) = @_;
if ( $err ) {
$self->{'.cgi_error'} = $err;
$self->{'.globals'}->{'FATAL'} == 1 ? croak $err
: $self->{'.globals'}->{'FATAL'} == 0 ? carp $err
: return $err;
}
return $self->{'.cgi_error'};
}
################# cgi-lib.pl Compatibility Methods #################
# Lightly GOLFED but the original functionality remains. You can call
# them using either: # $q->MethodName or CGI::Simple::MethodName
sub _shift_if_ref { shift if ref $_[0] eq 'CGI::Simple' }
sub ReadParse {
my $q = &_shift_if_ref || CGI::Simple->new;
my $pkg = caller();
no strict 'refs';
*in
= @_
? $_[0]
: *{"${pkg}::in"}; # set *in to passed glob or export *in
%in = $q->Vars;
$in{'CGI'} = $q;
return scalar %in;
}
sub SplitParam {
&_shift_if_ref;
defined $_[0]
&& ( wantarray ? split "\0", $_[0] : ( split "\0", $_[0] )[0] );
}
sub MethGet { request_method() eq 'GET' }
sub MethPost { request_method() eq 'POST' }
sub MyBaseUrl {
local $^W = 0;
'http://'
. server_name()
. ( server_port() != 80 ? ':' . server_port() : '' )
. script_name();
}
sub MyURL { MyBaseUrl() }
sub MyFullUrl {
local $^W = 0;
MyBaseUrl()
. $ENV{'PATH_INFO'}
. ( $ENV{'QUERY_STRING'} ? "?$ENV{'QUERY_STRING'}" : '' );
}
sub PrintHeader {
ref $_[0] ? $_[0]->header() : "Content-Type: text/html\n\n";
}
sub HtmlTop {
&_shift_if_ref;
"<html>\n<head>\n<title>$_[0]</title>\n</head>\n<body>\n<h1>$_[0]</h1>\n";
}
sub HtmlBot { "</body>\n</html>\n" }
sub PrintVariables { &_shift_if_ref; &Dump }
sub PrintEnv { &Dump( \%ENV ) }
sub CgiDie { CgiError( @_ ); die @_ }
sub CgiError {
&_shift_if_ref;
@_
= @_
? @_
: ( "Error: script " . MyFullUrl() . " encountered fatal error\n" );
( run in 0.534 second using v1.01-cache-2.11-cpan-ceb78f64989 )