ASP4

 view release on metacpan or  search on metacpan

lib/ASP4/Server.pm  view on Meta::CPAN

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

=head2 HTMLEncode( $str )

Performs a simple string substitution to sanitize C<$str> for inclusion on HTML pages.

Removes the threat of cross-site-scripting (XSS).

Eg:

  <tag/>

Becomes:

  &lt;tag/&gt;

=head2 HTMLDecode( $str )

Does exactly the reverse of HTMLEncode.

Eg:

  &lt;tag/&gt;

Becomes:

  <tag/>

=head2 URLEncode( $str )

Converts a string for use within a URL.

eg:

  test@test.com

becomes:

  test%40test.com

=head2 URLDecode( $str )

Converts a url-encoded string to a normal string.

eg:



( run in 0.920 second using v1.01-cache-2.11-cpan-39bf76dae61 )