Mojo::Server - HTTP server base class
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); }
Mojo::Server is an abstract HTTP server base class.
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.
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.
Mojolicious, Mojolicious::Guides, http://mojolicio.us.
To install Mojolicious, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Mojolicious
CPAN shell
perl -MCPAN -e shell install Mojolicious
For more information on module installation, please visit the detailed CPAN module installation guide.