NAME

Mojo::Server - HTTP Server Base Class

SYNOPSIS

use base 'Mojo::Server';

sub run {
    my $self = shift;

    # Get a transaction
    my $tx = $self->build_tx_cb->($self);

    # Call the handler
    $tx = $self->handler_cb->($self);
}

DESCRIPTION

Mojo::Server is a HTTP server base class. Subclasses should implement their own run method.

The usual request cycle is like this.

1. Build a new Mojo::Transaction objct with ->build_tx_cb
2. Read request information from client
3. Put request information into the transaction object
4. Call ->handler_cb to build a response
5. Get response information from the transaction object
6. Write response information to client

ATTRIBUTES

app

my $app = $server->app;
$server = $server->app(MojoSubclass->new);

Returns the instantiated Mojo application to serve. Overrides app_class if defined.

app_class

my $app_class = $server->app_class;
$server       = $server->app_class('MojoSubclass');

Returns the class name of the Mojo application to serve. Defaults to $ENV{MOJO_APP} and falls back to Mojo::HelloWorld.

build_tx_cb

my $btx = $server->build_tx_cb;
$server = $server->build_tx_cb(sub {
    my $self = shift;
    return Mojo::Transaction->new;
});

continue_handler_cb

my $handler = $server->continue_handler_cb;
$server     = $server->continue_handler_cb(sub {
    my ($self, $tx) = @_;
    return $tx;
});

handler_cb

my $handler = $server->handler_cb;
$server     = $server->handler_cb(sub {
    my ($self, $tx) = @_;
    return $tx;
});

METHODS

Mojo::Server inherits all methods from Mojo::Base and implements the following new ones.

log

$server->log('Test 123');

run

$server->run;

BUNDLED SERVERS

Mojo::Server::CGI - Serves a single CGI request.

Mojo::Server::Daemon - Portable standalone HTTP server.

Mojo::Server::Daemon::Prefork - Preforking standalone HTTP server.

Mojo::Server::FastCGI - A FastCGI server.