Apache2-ASP
view release on metacpan or search on metacpan
lib/Apache2/ASP/Server.pm view on Meta::CPAN
}# end URLEncode()
#==============================================================================
sub URLDecode
{
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 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;
return $str;
}# end HTMLEncode()
#==============================================================================
sub MapPath
{
my ($s, $path) = @_;
return unless defined($path);
$s->context->config->web->www_root . $path;
}# end MapPath()
#==============================================================================
sub Mail
{
my ($s, %args) = @_;
# XXX: Base64-encode the content, and update the content-type to reflect that
# if content-type === 'text/html'.
# XXX: Consider updating this so that we can send attachments as well.
Mail::Sendmail::sendmail( %args );
}# end Mail()
#==============================================================================
sub RegisterCleanup
{
my ($s, $sub, @args) = @_;
# This works both in "testing" mode and within a live mod_perl environment.
$s->context->get_prop('r')->pool->cleanup_register( $sub, \@args );
}# end RegisterCleanup()
#==============================================================================
sub _utf8_chr
{
my ($c) = @_;
require utf8;
my $u = chr($c);
utf8::encode($u); # drop utf8 flag
return $u;
}# end _utf8_chr()
#==============================================================================
sub DESTROY
{
my $s = shift;
undef(%$s);
}# end DESTROY()
1;# return true:
=pod
=head1 NAME
Apache2::ASP::Server - Utility methods for Apache2::ASP
=head1 SYNOPSIS
my $full_path = $Server->MapPath('/index.asp');
$Server->URLEncode( 'user@email.com' );
$Server->URLDecode( 'user%40email.com' );
$Server->HTMLEncode( '<br />' );
$Server->HTMLDecode( '<br />' );
$Server->Mail(
To => 'user@email.com',
From => '"Friendly Name" <friendly.name@email.com>',
Subject => 'Hello World',
Message => "E Pluribus Unum.\n"x777
);
( run in 0.822 second using v1.01-cache-2.11-cpan-e1769b4cff6 )