Froody
view release on metacpan or search on metacpan
lib/Froody/Server.pm view on Meta::CPAN
=head1 NAME
Froody::Server - baseclass for Froody::Server
=head1 DESCRIPTION
A Froody server. use as:
#!/usr/bin/perl
use warnings;
use strict;
use Froody::Server;
Froody::Server->dispatch();
..in a CGI script that is a Froody endpoint.
This server accepts a CGI request as the Froody request, and will dispatch
the method, and return the XML of the response as the result of the HTTP
request. If the dispatcher throws an error, we catch it and wrap it in
a L<Froody::Response> object that represents the error.
You can pass a namespace to dispatch into to the L<dispatch()> call, to
override the default L<Froody::Dispatch> namespace. This is strongly
recommended, or your code will be fairly useless.
=cut
package Froody::Server;
use base qw( Froody::Base );
use warnings;
use strict;
use CGI;
use Scalar::Util qw( blessed );
use Params::Validate qw(:all);
use Froody::Dispatch;
use Froody::Response;
use Froody::Logger;
my $logger = get_logger("froody.server");
use Froody::Renderer::json;
# XXX: move down to autoload when doing autodetect
eval q{
use Apache::Constants;
use Froody::Request::Apache;
use Froody::Server::Apache;
};
use Froody::Server::CGI;
=head1 METHODS
=over 4
=item dispatch()
Detects the environment that the Froody server is running under, assembles
a request, and dispatches it. Replies to the request with the XML response.
=cut
sub dispatch {
my $class = shift;
my $server = $class->server_class->new;
my $request = $server->request_class->new;
my $response = $class->dispatcher->dispatch(
method => $request->method,
params => $request->params || {},
);
# lookup what type of output the request asked for then send
( run in 1.398 second using v1.01-cache-2.11-cpan-39bf76dae61 )