NAME
AnyEvent::HTTPD::Request - A web application request handle for AnyEvent::HTTPD
DESCRIPTION
This is the request object as generated by AnyEvent::HTTPD and given in the request callbacks.
METHODS
- url
-
This method returns the URL of the current request.
- form ($content, $callback)
-
This method will create a form for you and bind it to the
$handler
you gave. The content of the form tag can be given by$content
, which can either be a string or a code reference, which will be called and should return the form content.When the form is submitted the
$callback
will be called before the submit request executes any of your content callbacks. The form ID is transmitted via a hidden input element with the name_APP_SRV_FORM_ID
, and you should take care not to use that form element name yourself.The
$callback
will receive as first argument the AnyEvent::HTTPD object.You can access the transmitted form parameters via the
parm
method. - respond ([$res])
-
This method will send a response to the request. If no
$res
argument was given eventually accumulated output will be send astext/html
.Otherwise
$res
can be:an array reference
Then the array reference has these elements:
my ($code, $message, $header_hash, $content) = [200, 'ok', { 'Content-Type' => 'text/html' }, '<h1>Test</h1>' }]
a hash reference
If it was a hash reference the hash is first searched for the
redirect
key and if that key does not exist for thecontent
key.The value for the
redirect
key should contain the URL that you want to redirect the request to.The value for the
content
key should contain an array reference with the first value being the content type and the second the content.
Here is an example:
$httpd->reg_cb ( '/image/elmex' => sub { my ($httpd, $req) = @_; open IMG, "$ENV{HOME}/media/images/elmex.png" or $req->respond ( [404, 'not found', { 'Content-Type' => 'text/plain' }, 'not found'] ); $req->respond ({ content => ['image/png', do { local $/; <IMG> }] }); } );
- link ($label, $callback, $newurl)
-
This method returns a html link which will call
$callback
when the user follows the link. It uses the_afid
param name, so take care not to use it for other things.$newurl
should be undef or the new (local) destination url, see also theurl
method above. - parm ($key)
-
Returns the first value of the form parameter
$key
or undef. - content
-
Returns the request content or undef if only parameters for a form were transmitted.
- o ($str)
-
This method appends
$str
to the response output of this request. The accumulated output can be sent back as 'text/html' by calling therespond
method without an argument.
COPYRIGHT & LICENSE
Copyright 2008 Robin Redeker, all rights reserved.
This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.