NAME
Mojo::Server - HTTP Server Base Class
SYNOPSIS
use Mojo::Base 'Mojo::Server';
sub run {
my $self = shift;
# Get a transaction
my $tx = $self->on_transaction->($self);
# Call the handler
$tx = $self->on_request->($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_request
my $handler = $server->on_request;
$server = $server->on_request(sub {
my ($self, $tx) = @_;
});
Callback to be invoked for requests that need a response.
on_transaction
my $btx = $server->on_transaction;
$server = $server->on_transaction(sub {
my $self = shift;
return Mojo::Transaction::HTTP->new;
});
Callback to be invoked when a new transaction is needed.
on_websocket
my $handshake = $server->on_websocket;
$server = $server->on_websocket(sub {
my ($self, $tx) = @_;
});
Callback to be invoked for WebSocket handshakes.
METHODS
Mojo::Server inherits all methods from Mojo::Base and implements the following new ones.
load_app
my $app = $server->load_app('./myapp.pl');
Load application from script. Note that this method is EXPERIMENTAL and might change without warning!
print Mojo::Server->new->load_app('./myapp.pl')->home;
run
$server->run;
Start server.