Apache2-ASP
view release on metacpan or search on metacpan
lib/Apache2/ASP/SimpleCGI.pm view on Meta::CPAN
no warnings 'uninitialized';
if( exists( $s->{uploads}->{$key} ) )
{
my $upload = $s->{uploads}->{$key};
if( exists( $upload->{$info} ) )
{
return $upload->{$info};
}
else
{
return undef;
}# end if()
}
else
{
return undef;
}# end if()
}# end upload_info()
#==============================================================================
sub param
{
my ($s, $key) = @_;
if( defined($key) )
{
if( ref($s->{params}->{$key}) )
{
return wantarray ? @{ $s->{params}->{$key} } : $s->{params}->{$key};
}
else
{
return $s->{params}->{$key};
}# end if()
}
else
{
return keys(%{ $s->{params} });
}# end if()
}# end param()
#==============================================================================
sub escape
{
my $toencode = $_[1];
no warnings 'uninitialized';
$toencode =~ s/([^a-zA-Z0-9_\-.])/uc sprintf("%%%02x",ord($1))/esg;
$toencode;
}# end escape()
#==============================================================================
sub unescape
{
my ($s, $todecode) = @_;
return unless defined($todecode);
$todecode =~ tr/+/ /; # pluses become spaces
$todecode =~ s/%(?:([0-9a-fA-F]{2})|u([0-9a-fA-F]{4}))/
defined($1)? chr hex($1) : utf8_chr(hex($2))/ge;
return $todecode;
}# end unescape()
#==============================================================================
sub DESTROY
{
my $s = shift;
map { close($s->{uploads}->{$_}->{filehandle}) }
keys(%{$s->{uploads}});
}# end DESTROY()
1;# return true:
=pod
=head1 NAME
Apache2::ASP::SimpleCGI - Basic CGI functionality
=head1 SYNOPSIS
use Apache2::ASP::SimpleCGI;
my $cgi = Apache2::ASP::SimpleCGI->new(
content_type => 'multipart/form-data',
content_length => 1200,
querystring => 'mode=create&uploadID=234234',
body => ...
);
my $val = $cgi->param('mode');
foreach my $key ( $cgi->param )
{
print $key . ' --> ' . $cgi->param( $key ) . "\n";
}# end foreach()
my $escaped = $cgi->escape( 'Hello world' );
my $unescaped = $cgi->unescape( 'Hello+world' );
my $upload = $cgi->upload('filename');
my $filehandle = $cgi->upload_info('filename', 'filehandle' );
=head1 DESCRIPTION
This package provides basic CGI functionality and is also used for testing and
in the API enironment.
C<Apache2::ASP::SimpleCGI> uses L<HTTP::Body> under the hood.
=head1 PUBLIC METHODS
=head2 new( %args )
Returns a new C<Apache2::ASP::SimpleCGI> object.
C<%args> can contain C<content_type>, C<content_length>, C<querystring> and C<body>.
( run in 0.937 second using v1.01-cache-2.11-cpan-39bf76dae61 )