ASP4
view release on metacpan or search on metacpan
lib/ASP4.pm view on Meta::CPAN
/foo.asp?name=joe&color=red
...produces the following C<$Form> object:
$VAR1 = {
name => 'joe',
color => 'red'
};
Access form data just like any other hashref:
Hello, <%= $Form->{name} %>, I see your favorite color is <%= $Form->{color} %>.
=head2 $Server
The C<$Server> object offers a few utility methods that don't really fit anywhere else.
=head3 $Server->HTMLEncode( $string )
Given a string like C<< <br/> >> returns a string like C<< <br/> >>
=head3 $Server->HTMLDecode( $string )
Given a string like C<< <br/> >> returns a string like C<< <br/> >>
=head3 $Server->URLEncode( $string )
Given a string like C<< billg@microsoft.com >> returns a string like C<< billg%40microsoft.com >>
=head3 $Server->URLDecode( $string )
Given a string like C<< billg%40microsoft.com >> returns a string like C<< billg@microsoft.com >>
=head3 $Server->MapPath( $path )
Given a C<$path> of C</foo.asp> would return something like C</var/www/example.com/htdocs/foo.asp>
=head3 $Server->Mail( %args )
Sends an email via L<Mail::Sendmail>. In fact it simply calls the C<sendmail(...)> function
provided by L<Mail::Sendmail>.
Simple Example:
$Server->Mail(
from => 'foo@bar.com',
to => 'bar@foo.com',
subject => 'Hello, world!',
message => 'this is a test message'
);
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 L<Mail::Sendmail> for further details and examples.
=head3 $Server->RegisterCleanup( sub { ... }, \@args )
After the final response has been sent to the client, the server will execute
your subref and provide it the C<\@args> passed in.
This is useful for long-running or asynchronous processes that don't require the
client to wait for a response.
=head2 $Request
An instance of L<ASP4::Request>, the C<$Request> object contains specialized methods
for dealing with whatever the browser sent us.
Examples:
=head3 $Request->Cookies( $name )
my $cookie = $Request->Cookies("some-cookie-name");
=head3 $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 L<ASP4::FileUpload> documentation.
=head2 $Response
An instance of L<ASP4::Response>, the C<$Response> object gives shortcuts for dealing
with the outgoing reply from the server back to the client.
Examples:
=head3 $Response->Write( $string )
The following example prints the string C<Hello, World!> to the browser:
$Response->Write("Hello, World!");
Or, within an ASP script, C<< <%= "Hello, World" %> >>
=head3 $Response->Redirect( $url )
$Response->Redirect( "/new/url/?foo=bar" );
=head3 $Response->SetCookie( %args )
( run in 0.703 second using v1.01-cache-2.11-cpan-754626df90b )