DiaColloDB::WWW::Handler - diachronic collocation db, www wrappers: abstract handler class API
##======================================================================== ## PRELIMINARIES use DiaColloDB::WWW::Handler; ##======================================================================== ## API $h = $class_or_obj->new(%options); $bool = $h->prepare($server,$path); $rsp = $h->run($server, $clientConn, $httpRequest); undef = $h->finish($server, $clientConn); ##======================================================================== ## Generic Utilities $rsp = $h->headResponse(); $rsp = $CLASS_OR_OBJECT->response($code=RC_OK, $msg=status_message($code), $hdr, $content); undef = $h->cerror($csock, $status=RC_INTERNAL_SERVER_ERROR, @msg); $rsp = $h->dumpResponse(\$contentRef, %opts);
DiaColloDB::WWW::Handler is an abstract API for request handlers used by DiaColloDB::WWW::Server.
DiaColloDB::WWW::Handler inherits from DiaColloDB::Logger.
$h = $class_or_obj->new(%options);
constructor.
$rsp = $h->run($server, $clientConn, $httpRequest);
Handle a single request. Parameters:
The server which received the request, a DiaColloDB::WWW::Server object.
The client connect socket to which the response is to be sent.
An HTTP::Request object representing the client request.
The method should return a HTTP::Response object to be passed back to the client. If the call die()s or returns undef, $server should generate an appropriate error response and send it to the client instead if it the connection is still open.
undef
$server
This method may return the data to the client itself; if so, it should close the client connection ($csock->shutdown(2); $csock->close()) and return undef to prevent bogus error messages.
$csock->shutdown(2); $csock->close()
undef = $h->finish($server, $clientConn);
Clean up handler state after run(); default implementation does nothing.
$rsp = $h->headResponse(); $rsp = $h->headResponse(\@headers); $rsp = $h->headResponse($httpHeaders);
Rudimentary handling for HEAD requests; always returns HTTP::Status::RC_OK.
$rsp = $CLASS_OR_OBJECT->response($code, $msg, $hdr, $content);
Generate an HTTP::Response object with status code $code, status message $msg, header(s) $hdr, and (optional) content $content. $code defaults to HTTP::Status::RC_OK, $msg defaults to status_message($code), adn $hdr may be an HTTP::Headers object, an ARRAY-ref or a HASH-ref. Wraps HTTP::Response->new().
$code
$msg
$hdr
$content
undef = $h->cerror($csock, $status=RC_INTERNAL_SERVER_ERROR, @msg);
Creates an error response and sends it to the client socket; also logs the error at level ($c->{logError}||'warn') and shuts down the socket.
$rsp = $h->dumpResponse(\$contentRef, %opts);
Create and return a new data-dump response. Known %opts:
raw => $bool, ##-- return raw data (text/plain) ; default=$h->{returnRaw} type => $mimetype, ##-- mime type if not raw mode charset => $enc, ##-- character set, if not raw mode filename => $file, ##-- attachment name, if not raw mode
Bryan Jurish <moocow@cpan.org>
Copyright (C) 2016 by Bryan Jurish
This package is free software; you can redistribute it and/or modify it under the same terms as Perl itself, either Perl version 5.14.2 or, at your option, any later version of Perl 5 you may have available.
DiaColloDB::WWW::Handler::cgi(3pm), DiaColloDB::WWW::Handler::static(3pm), DiaColloDB::WWW::Server(3pm), perl(1), ...
To install DiaColloDB::WWW, copy and paste the appropriate command in to your terminal.
cpanm
cpanm DiaColloDB::WWW
CPAN shell
perl -MCPAN -e shell install DiaColloDB::WWW
For more information on module installation, please visit the detailed CPAN module installation guide.