Skip to content

Commit

Permalink
fixed arguments of upgrade event in Mojo::Transaction::HTTP
Browse files Browse the repository at this point in the history
  • Loading branch information
kraih committed Oct 19, 2011
1 parent 225a38d commit 6d8ff66
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 8 deletions.
1 change: 1 addition & 0 deletions Changes
Expand Up @@ -4,6 +4,7 @@ This file documents the revision history for Perl extension Mojolicious.
- Added EXPERIMENTAL upgrade event to Mojo::Content::Single.
- Added EXPERIMENTAL part event to Mojo::Content::MultiPart.
- Improved documentation.
- Fixed arguments of upgrade event in Mojo::Transaction::HTTP.

2.0 2011-10-17 00:00:00
- Code name "Leaf Fluttering In Wind", this is a major release.
Expand Down
10 changes: 5 additions & 5 deletions lib/Mojo/Server/Daemon.pm
Expand Up @@ -117,7 +117,7 @@ sub _build_tx {
);

# Upgrade
$tx->on(upgrade => sub { $self->_upgrade($id, pop) });
$tx->on(upgrade => sub { $self->_upgrade($id, $_[1]) });

# New request on the connection
$c->{requests} ||= 0;
Expand Down Expand Up @@ -288,10 +288,10 @@ sub _read {
}

sub _upgrade {
my ($self, $id, $txref) = @_;
return unless $$txref->req->headers->upgrade =~ /WebSocket/i;
my $c = $self->{connections}->{$id};
$c->{websocket} = $$txref = $self->upgrade_tx($$txref);
my $self = shift;
return unless $_[1]->req->headers->upgrade =~ /WebSocket/i;
my $c = $self->{connections}->{$_[0]};
$c->{websocket} = $_[1] = $self->upgrade_tx($_[1]);
}

sub _user {
Expand Down
4 changes: 2 additions & 2 deletions lib/Mojo/Transaction/HTTP.pm
Expand Up @@ -186,7 +186,7 @@ sub server_read {
# EOF
elsif ((length $chunk == 0) || ($req->is_done && !$self->{handled}++)) {
my $ws = $self;
$self->emit(upgrade => \$ws) if $req->headers->upgrade;
$self->emit(upgrade => $ws) if $req->headers->upgrade;
$self->emit(request => $ws);
}

Expand Down Expand Up @@ -357,7 +357,7 @@ Emitted when a request needs to be handled.
=head2 C<upgrade>
$tx->on(upgrade => sub {
my ($tx, $txref) = @_;
my ($tx, $ws) = @_;
});
Emitted when a connection needs to be upgraded.
Expand Down
16 changes: 15 additions & 1 deletion t/mojo/eventemitter.t
@@ -1,7 +1,7 @@
#!/usr/bin/env perl
use Mojo::Base -strict;

use Test::More tests => 42;
use Test::More tests => 46;

# "Hi, Super Nintendo Chalmers!"
use_ok 'Mojo::EventEmitter';
Expand Down Expand Up @@ -127,3 +127,17 @@ is $e->has_subscribers('foo'), undef, 'no subscribers';
is scalar @{$e->subscribers('foo')}, 0, 'no subscribers';
$e->emit('foo');
is $counter, 5, 'event was not emitted again';

# Pass by reference
$e = Mojo::EventEmitter->new;
my $buffer = '';
$e->on(one => sub { $_[1] .= 'abc' . $_[2] });
$e->on(one => sub { $_[1] .= '123' . pop });
is $buffer, '', 'right result';
$e->emit(one => $buffer => 'two');
is $buffer, 'abctwo123two', 'right result';
$e->once(one => sub { $_[1] .= 'def' });
$e->emit(one => $buffer => 'three');
is $buffer, 'abctwo123twoabcthree123threedef', 'right result';
$e->emit(one => $buffer => 'x');
is $buffer, 'abctwo123twoabcthree123threedefabcx123x', 'right result';

0 comments on commit 6d8ff66

Please sign in to comment.