Skip to content

Commit

Permalink
removed transaction and upgrade events from Mojo::Server
Browse files Browse the repository at this point in the history
  • Loading branch information
kraih committed Oct 12, 2011
1 parent 992db45 commit 1159ceb
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 54 deletions.
66 changes: 18 additions & 48 deletions lib/Mojo/Server.pm
Expand Up @@ -17,26 +17,14 @@ has app_class =>

sub new {
my $self = shift->SUPER::new(@_);

# Events
$self->on_request(sub { shift->app->handler(shift) });
$self->on_transaction(
sub {
my ($self, $txref) = @_;
$$txref = $self->app->build_tx;
}
);
$self->on_upgrade(
sub {
my ($self, $txref) = @_;
$$txref = $self->app->upgrade_tx($$txref);
$$txref->server_handshake;
}
);

return $self;
}

sub build_tx { shift->app->build_tx }

sub upgrade_tx { shift->app->upgrade_tx(shift)->server_handshake }

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

Expand Down Expand Up @@ -65,9 +53,7 @@ EOF
return $app;
}

sub on_request { shift->on(request => shift) }
sub on_transaction { shift->on(transaction => shift) }
sub on_upgrade { shift->on(upgrade => shift) }
sub on_request { shift->on(request => shift) }

# "Are you saying you're never going to eat any animal again? What about
# bacon?
Expand All @@ -94,7 +80,7 @@ Mojo::Server - HTTP server base class
my $self = shift;
# Get a transaction
$self->emit(transaction => \(my $tx));
my $tx = $self->build_tx;
# Emit request
$self->emit(request => $tx);
Expand All @@ -116,22 +102,6 @@ L<Mojo::Server> can emit the following events.
Emitted for requests that need a response.
=head2 C<transaction>
$server->on(request => sub {
my ($server, $txref) = @_;
});
Emitted when a new transaction is needed.
=head2 C<upgrade>
$server->on(upgrade => sub {
my ($server, $txref) = @_;
});
Emitted when a transaction needs to be upgraded.
=head1 ATTRIBUTES
L<Mojo::Server> implements the following attributes.
Expand Down Expand Up @@ -162,6 +132,12 @@ implements the following new ones.
Construct a new L<Mojo::Server> object.
=head2 C<build_tx>
my $tx = $server->build_tx;
Let application build a transaction.
=head2 C<load_app>
my $app = $server->load_app('./myapp.pl');
Expand All @@ -177,24 +153,18 @@ Note that this method is EXPERIMENTAL and might change without warning!
Register C<request> event.
=head2 C<on_transaction>
$server->on_transaction(sub {...});
Register C<transaction> event.
=head2 C<on_upgrade>
$server->on_upgrade(sub {...});
Register C<upgrade> event.
=head2 C<run>
$server->run;
Start server.
=head2 C<upgrade_tx>
my $ws = $server->upgrade_tx(tx);
Let application upgrade transaction.
=head1 SEE ALSO
L<Mojolicious>, L<Mojolicious::Guides>, L<http://mojolicio.us>.
Expand Down
2 changes: 1 addition & 1 deletion lib/Mojo/Server/CGI.pm
Expand Up @@ -12,7 +12,7 @@ sub run {
my $self = shift;

# Environment
$self->emit(transaction => \(my $tx));
my $tx = $self->build_tx;
my $req = $tx->req;
$req->parse(\%ENV);

Expand Down
5 changes: 2 additions & 3 deletions lib/Mojo/Server/Daemon.pm
Expand Up @@ -88,7 +88,7 @@ sub _build_tx {
my ($self, $id, $c) = @_;

# Build transaction
$self->emit(transaction => \(my $tx));
my $tx = $self->build_tx;
$tx->connection($id);

# Identify
Expand Down Expand Up @@ -294,8 +294,7 @@ sub _upgrade {
my ($self, $id, $txref) = @_;
return unless $$txref->req->headers->upgrade =~ /WebSocket/i;
my $c = $self->{connections}->{$id};
$self->emit(upgrade => $txref);
$c->{websocket} = $$txref;
$c->{websocket} = $$txref = $self->upgrade_tx($$txref);
}

sub _user {
Expand Down
2 changes: 1 addition & 1 deletion lib/Mojo/Server/PSGI.pm
Expand Up @@ -11,7 +11,7 @@ sub run {
my ($self, $env) = @_;

# Environment
$self->emit(transaction => \(my $tx));
my $tx = $self->build_tx;
my $req = $tx->req;
$req->parse($env);

Expand Down
2 changes: 1 addition & 1 deletion lib/Mojo/Transaction/HTTP.pm
Expand Up @@ -221,7 +221,7 @@ sub server_read {
$self->emit(upgrade => \$ws) if $req->headers->upgrade;

# Handle request
$self->emit(request => $ws->is_websocket ? $ws : $self);
$self->emit(request => $ws);

# Protect handler from incoming pipelined requests
$self->{handled} = 1;
Expand Down

0 comments on commit 1159ceb

Please sign in to comment.