Skip to content

Commit

Permalink
added experimental handler method to Mojo::Server
Browse files Browse the repository at this point in the history
  • Loading branch information
kraih committed Oct 27, 2011
1 parent 6fd822a commit 6b463c1
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 6 deletions.
1 change: 1 addition & 0 deletions Changes
Expand Up @@ -3,6 +3,7 @@ This file documents the revision history for Perl extension Mojolicious.
2.12 2011-10-27 00:00:00
- Added EXPERIMENTAL cleanup_interval attribute to Mojo::IOLoop.
- Added EXPERIMENTAL max_leftover_size attribute to Mojo::Content.
- Added EXPERIMENTAL handler method to Mojo::Server.
- Replaced handle method in Mojo::IOLoop with stream method.
- Replaced writing and not_writing methods in Mojo::IOWatcher with
watch method.
Expand Down
13 changes: 11 additions & 2 deletions lib/Mojo/Server.pm
Expand Up @@ -23,6 +23,8 @@ sub new {

sub build_tx { shift->app->build_tx }

sub handler { shift->emit(request => @_) }

sub load_app {
my ($self, $file) = @_;

Expand Down Expand Up @@ -86,8 +88,8 @@ Mojo::Server - HTTP server base class
# Get a transaction
my $tx = $self->build_tx;
# Emit request
$self->emit(request => $tx);
# Handle request
$self->handler($tx);
}
=head1 DESCRIPTION
Expand Down Expand Up @@ -150,6 +152,13 @@ Construct a new L<Mojo::Server> object.
Let application build a transaction.
=head2 C<handler>
$server->handler($tx);
Emit C<request> event.
Note that this method is EXPERIMENTAL and might change without warning!
=head2 C<load_app>
my $app = $server->load_app('./myapp.pl');
Expand Down
2 changes: 1 addition & 1 deletion lib/Mojo/Server/CGI.pm
Expand Up @@ -29,7 +29,7 @@ sub run {
}

# Handle
$self->emit(request => $tx);
$self->handler($tx);

# Response start line
STDOUT->autoflush(1);
Expand Down
4 changes: 2 additions & 2 deletions lib/Mojo/Server/Daemon.pm
Expand Up @@ -115,11 +115,11 @@ sub _build_tx {
# WebSocket
if ($ws) {
$self->{connections}->{$id}->{websocket} = $ws->server_handshake;
$self->emit(request => $ws);
$self->handler($ws);
}

# HTTP
$self->emit(request => $tx);
$self->handler($tx);

# Resume
$tx->on(resume => sub { $self->_write($id) });
Expand Down
2 changes: 1 addition & 1 deletion lib/Mojo/Server/PSGI.pm
Expand Up @@ -31,7 +31,7 @@ sub run {
}

# Handle
$self->emit(request => $tx);
$self->handler($tx);

# Response headers
my $res = $tx->res;
Expand Down

0 comments on commit 6b463c1

Please sign in to comment.