ASP4

 view release on metacpan or  search on metacpan

README.markdown  view on Meta::CPAN

    );

To send an HTML email do the following:

    use MIME::Base64;
    $Server->Mail(
      from                        => 'foo@bar.com',
      to                          => 'bar@foo.com',
      subject                     => 'Hello, world!',
      'content-type'              => 'text/html',
      'content-transfer-encoding' => 'base64',
      message => encode_base64(<<"HTML")
    <html>
    <body>
      <p>This is an html email.</p>
      <p>You can see that <b>this text is bold</b>.</p>
    </body>
    </html>
    HTML
    );

Please see [Mail::Sendmail](http://search.cpan.org/perldoc?Mail::Sendmail) for further details and examples.

### $Server->RegisterCleanup( sub { ... }, \@args )

After the final response has been sent to the client, the server will execute
your subref and provide it the `\@args` passed in.

This is useful for long-running or asynchronous processes that don't require the
client to wait for a response.

## $Request

An instance of [ASP4::Request](http://search.cpan.org/perldoc?ASP4::Request), the `$Request` object contains specialized methods
for dealing with whatever the browser sent us.

Examples:

### $Request->Cookies( $name )

    my $cookie = $Request->Cookies("some-cookie-name");

### $Request->FileUpload( $field_name )

    if( my $file = $Request->FileUpload('avatar_pic') ) {
      # Handle the uploaded file:
      $file->SaveAs( "/var/media/$Session->{user_id}/avatar/" . $file->FileName );
    }

See also the [ASP4::FileUpload](http://search.cpan.org/perldoc?ASP4::FileUpload) documentation.

## $Response

An instance of [ASP4::Response](http://search.cpan.org/perldoc?ASP4::Response), the `$Response` object gives shortcuts for dealing
with the outgoing reply from the server back to the client.

Examples:

### $Response->Write( $string )

The following example prints the string `Hello, World!` to the browser:

    $Response->Write("Hello, World!");

Or, within an ASP script, `<%= "Hello, World" %>`

### $Response->Redirect( $url )

    $Response->Redirect( "/new/url/?foo=bar" );

### $Response->SetCookie( %args )

Setting cookies works as follows:

    $Response->SetCookie(
      name  => "cookie-name",
      value => "the-value",
      

    # The rest of these arguments are optional:
    

    # Expires: (If you don't specify the "expires" argument, the cookie will
    # be deleted when the browser is closed.
    expires => "3D",  # 3 days
    expires => "3H",  # or 3 hours
    expires => "3M",  # or 3 minutes
    

    # Domain: (defaults to $ENV{HTTP_HOST})
    domain  => ".example.com",    # works for *.example.com
    domain  => "www.example.com", # will ONLY work for www.example.com
    

      # Path:
      path    => "/some/folder/"    # will ONLY work within /some/folder/ on your website
    );

### $Response->Include( $path, %args )

ASP4's `$Response` object offers 3 different include methods.

    <!-- Normal SSI-style Include -->
    <!-- #include virtual="/includes/page.asp" -->

If you want to supply arguments to the included ASP script you can use `$Response->Include($path, \%args)`

    # Add the output of C</includes/page.asp> to the current output buffer:
    my %args = ( foo => "bar" );
    $Response->Include( $Server->MapPath("/includes/page.asp"), \%args );

`\%args` is optional.

Within the included ASP script, `\%args` is accessible like this:

    <%
      my ($self, $context, $args) = @_;
    %>

### $Response->TrapInclude( $path, %args )



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