The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.

NAME

Mojo::Server - HTTP Server Base Class

SYNOPSIS

use base 'Mojo::Server';

sub run {
    my $self = shift;

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

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

DESCRIPTION

Mojo::Server is an abstract HTTP server base class.

ATTRIBUTES

Mojo::Server implements the following attributes.

app

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

Application this server handles, defaults to a Mojo::HelloWorld object.

app_class

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

Class of the application this server handles, defaults to Mojo::HelloWorld.

on_build_tx

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

Transaction builder callback.

on_handler

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

Handler callback.

on_websocket_handshake

my $handshake = $server->on_websocket_handshake;
$server       = $server->on_websocket_handshake(sub {
    my ($self, $tx) = @_;
});

WebSocket handshake callback.

reload

my $reload = $server->reload;
$server    = $server->reload(1);

Activate automatic reloading.

METHODS

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

run

$server->run;

Start server.

SEE ALSO

Mojolicious, Mojolicious::Guides, http://mojolicious.org.