Apache2-ASP
view release on metacpan or search on metacpan
lib/Apache2/ASP/ModPerl2CGI.pm view on Meta::CPAN
else
{
$s->req( Apache2::Request->new( $r ) );
}# end if()
return $s;
}# end new()
#==============================================================================
sub escape
{
my ($s, $str) = @_;
return Apache2::ASP::SimpleCGI->escape( $str );
}# end escape()
#==============================================================================
sub unescape
{
my ($s, $str) = @_;
return Apache2::ASP::SimpleCGI->unescape( $str );
}# end unescape()
#==============================================================================
sub AUTOLOAD
{
my $s = shift;
our $AUTOLOAD;
my ($name) = $AUTOLOAD =~ m/([^:]+)$/;
eval { return $s->{r}->$name( @_ ) };
confess $@ if $@;
lib/Apache2/ASP/Request.pm view on Meta::CPAN
#==============================================================================
sub Cookies
{
my $s = shift;
return { } unless $s->context->headers_in->{cookie};
my %out = ( );
foreach my $item ( split /;\s*/, $s->context->headers_in->{cookie} )
{
my ( $name, $val ) = map { $s->context->cgi->unescape( $_ ) } split /\=/, $item;
$out{$name} = $val;
}# end foreach()
@_ ? $out{$_[0]} : \%out;
}# end Cookies()
#==============================================================================
sub FileUpload
{
lib/Apache2/ASP/Response.pm view on Meta::CPAN
{
my $s = shift;
my ($name, $val, $path, $expires) = @_;
die "Usage: Response.AddCookie(name, value [, path [, expires ]])"
unless defined($name) && defined($val);
$path ||= '/';
$expires ||= time() + ( 60 * 30 );
my $expire_date ||= time2str( $expires );
my $cookie = join '=', map { $s->context->cgi->escape( $_ ) } ( $name => $val );
$s->context->headers_out->push_header( 'set-cookie' => "$cookie; path=$path; expires=$expire_date" );
}# end AddCookie()
#==============================================================================
sub AddHeader
{
my ($s, $name, $val) = @_;
return unless defined($name) && defined($val);
lib/Apache2/ASP/Server.pm view on Meta::CPAN
don't belong anywhere else.
Keeping with that tradition, the Apache2::ASP Server object is a collection of
functions that don't belong anywhere else.
=head1 PUBLIC METHODS
=head2 URLEncode( $str )
Converts a string into its url-encoded equivalent. This approximates to
JavaScript's C<escape()> function or L<CGI>'s C<escape()> function.
Example:
<%= $Server->URLEncode( 'user@email.com' ) %>
Returns
user%40email.com
=head2 URLDecode( $str )
Converts a url-encoded string into its non-url-encoded equivalent. This works
the same way as JavaScript's and L<CGI>'s C<unescape()> function.
Example:
<%= $Server->URLDecode( 'user%40email.com' ) %>
Returns
user@email.com
=head2 HTMLEncode( $str )
lib/Apache2/ASP/SimpleCGI.pm view on Meta::CPAN
{
my ($s, %args) = @_;
my %params = ();
my %upload_data = ();
no warnings 'uninitialized';
if( length($args{querystring}) )
{
foreach my $part ( split /&/, $args{querystring} )
{
my ($k,$v) = map { $s->unescape($_) } split /\=/, $part;
if( exists($params{$k}) )
{
if( ref($params{$k}) )
{
push @{$params{$k}}, $v;
}
else
{
$params{$k} = [ $params{$k}, $v ];
lib/Apache2/ASP/SimpleCGI.pm view on Meta::CPAN
}# 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()
lib/Apache2/ASP/SimpleCGI.pm view on Meta::CPAN
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.
lib/Apache2/ASP/SimpleCGI.pm view on Meta::CPAN
Returns a new C<Apache2::ASP::SimpleCGI> object.
C<%args> can contain C<content_type>, C<content_length>, C<querystring> and C<body>.
=head2 param( [$key] )
If C<$key> is given, returns the value of the form or querystring parameter by that name.
If C<$key> is not given, returns a list of all parameter names.
=head2 escape( $str )
Returns a URL-encoded version of C<$str>.
=head2 unescape( $str )
Returns a URL-decoded version of C<$str>.
=head2 upload( $field_name )
Returns all of the information we have about a file upload named C<$field_name>.
=head2 upload_info( $field_name, $item_name )
Returns just that part of C<$field_name>'s upload info.
lib/Apache2/ASP/Test/UserAgent.pm view on Meta::CPAN
$response->header( 'Content-Type' => $s->context->response->{ContentType} );
foreach my $header ( $s->context->response->Headers )
{
while( my ($k,$v) = each(%$header) )
{
$response->header( $k => $v );
if( lc($k) eq 'set-cookie' )
{
my ($data) = split /;/, $v;
my ($name,$val) = map { Apache2::ASP::SimpleCGI->unescape( $_ ) } split /\=/, $data;
$s->add_cookie( $name => $val );
}# end if()
}# end while()
}# end foreach()
if( $s->context->session && $s->context->session->{SessionID} )
{
$s->add_cookie(
$s->context->config->data_connections->session->cookie_name => $s->context->session->{SessionID}
);
lib/Apache2/ASP/Test/UserAgent.pm view on Meta::CPAN
# User-Agent:
$req->header( 'User-Agent' => 'test-useragent v1.0' );
$ENV{HTTP_USER_AGENT} = 'test-useragent v1.0';
# Cookies:
my @cookies = ();
while( my ($name,$val) = each(%{ $s->{cookies} } ) )
{
next unless $name && $val;
push @cookies, "$name=" . Apache2::ASP::SimpleCGI->escape($val);
}# end while()
$req->header( 'Cookie' => join ';', @cookies ) if @cookies;
$ENV{HTTP_COOKIE} = join ';', @cookies;
$ENV{DOCUMENT_ROOT} = $docroot
if $docroot;
if( $ENV{REQUEST_METHOD} =~ m/^post$/i )
{
# Set up the basic params:
( run in 0.788 second using v1.01-cache-2.11-cpan-c21f80fb71c )