ASP4
view release on metacpan or search on metacpan
lib/ASP4/Server.pm view on Meta::CPAN
}# end new()
sub context { ASP4::HTTPContext->current }
sub URLEncode
{
ASP4::HTTPContext->current->cgi->escape( $_[1] );
}# end URLEncode()
sub URLDecode
{
ASP4::HTTPContext->current->cgi->unescape( $_[1] );
}# end URLDecode()
sub HTMLEncode
{
my ($s, $str) = @_;
no warnings 'uninitialized';
$str =~ s/&/&/g;
$str =~ s/</</g;
$str =~ s/>/>/g;
$str =~ s/"/"/g;
$str =~ s/'/'/g;
return $str;
}# end HTMLEncode()
sub HTMLDecode
{
my ($s, $str) = @_;
no warnings 'uninitialized';
$str =~ s/</</g;
$str =~ s/>/>/g;
$str =~ s/"/"/g;
$str =~ s/&/&/g;
$str =~ s/'/'/g;
return $str;
}# end HTMLDecode()
sub MapPath
{
my ($s, $path) = @_;
return unless defined($path);
ASP4::HTTPContext->current->config->web->www_root . $path;
}# end MapPath()
sub Mail
{
my $s = shift;
Mail::Sendmail::sendmail( @_ );
die $Mail::Sendmail::error if $Mail::Sendmail::error;
return $Mail::Sendmail::log;
}# end Mail()
sub RegisterCleanup
{
my ($s, $sub, @args) = @_;
$s->context->r->pool->cleanup_register( $sub, \@args );
}# end RegisterCleanup()
sub Error
{
my $s = shift;
my $error = ref($_[0]) && $_[0]->isa('ASP4::Error') ? $_[0] : ASP4::Error->new( @_ );
$s->context->stash->{error} = $error;
$s->context->config->load_class( $s->context->config->errors->error_handler );
my $error_handler = $s->context->config->errors->error_handler->new();
$error_handler->init_asp_objects( $s->context );
$error_handler->run( $s->context );
return $error;
}# end Error()
1;# return true:
=pod
=head1 NAME
ASP4::Server - Utility Methods
=head1 SYNOPSIS
# Get the full disk path to /contact/form.asp:
$Server->MapPath("/contact/form.asp");
# Email someone:
$Server->Mail(
To => 'jim@bob.com',
From => 'Joe Jangles <joe@jangles.net>',
Subject => 'Test Email',
Message => "Hello There!",
);
# Avoid XSS:
<input type="text" name="foo" value="<%= $Server->HTMLEncode( $Form->{foo} ) %>" />
# Proper URLs:
<a href="foo.asp?bar=<%= $Server->URLEncode($Form->{bar}) %>">Click</a>
=head1 DESCRIPTION
The C<$Server> object provides some utility methods that don't really fit anywhere
else, but are still important.
=head1 PUBLIC METHODS
( run in 0.742 second using v1.01-cache-2.11-cpan-39bf76dae61 )