Skip to content

Commit

Permalink
deprecated various on_* methods
Browse files Browse the repository at this point in the history
  • Loading branch information
kraih committed Oct 12, 2011
1 parent 1159ceb commit 666111f
Show file tree
Hide file tree
Showing 22 changed files with 186 additions and 202 deletions.
27 changes: 7 additions & 20 deletions lib/Mojo/Content.pm
Expand Up @@ -155,8 +155,13 @@ sub leftovers {
return $self->{buffer};
}

sub on_body { shift->on(body => shift) }
sub on_read { shift->on(read => shift) }
# DEPRECATED in Smiling Face With Sunglasses!
sub on_read {
warn <<EOF;
Mojo::Content->on_read is DEPRECATED in favor of using Mojo::Content->on!!!
EOF
shift->on(read => shift);
}

sub parse {
my $self = shift;
Expand Down Expand Up @@ -585,24 +590,6 @@ Check if body parsing started yet.
Remove leftover data from content parser.
=head2 C<on_body>
$content->on_body(sub {...});
Register C<body> event.
Note that this method is EXPERIMENTAL and might change without warning!
=head2 C<on_read>
$content->on_read(sub {...});
Register C<read> event.
$content->on_read(sub {
my ($content, $chunk) = @_;
say $chunk;
});
=head2 C<parse>
$content = $content->parse("Content-Length: 12\r\n\r\nHello World!");
Expand Down
42 changes: 17 additions & 25 deletions lib/Mojo/Message.pm
Expand Up @@ -52,7 +52,7 @@ sub body {
# Callback
if (ref $new eq 'CODE') {
weaken $self;
return $content->on_read(sub { $self->$new(pop) });
return $content->on(read => sub { $self->$new(pop) });
}

# Set text content
Expand Down Expand Up @@ -307,8 +307,22 @@ sub leftovers { shift->content->leftovers }

sub max_line_size { shift->headers->max_line_size(@_) }

sub on_finish { shift->on(finish => shift) }
sub on_progress { shift->on(progress => shift) }
# DEPRECATED in Smiling Face With Sunglasses!
sub on_finish {
warn <<EOF;
Mojo::Message->on_finish is DEPRECATED in favor of using Mojo::Message->on!!!
EOF
shift->on(finish => shift);
}

# DEPRECATED in Smiling Face With Sunglasses!
sub on_progress {
warn <<EOF;
Mojo::Message->on_progress is DEPRECATED in favor of using
Mojo::Message->on!!!
EOF
shift->on(progress => shift);
}

sub param {
my $self = shift;
Expand Down Expand Up @@ -775,28 +789,6 @@ Remove leftover data from message parser.
Maximum line size in bytes.
Note that this method is EXPERIMENTAL and might change without warning!
=head2 C<on_finish>
$message->on_finish(sub {...});
Register C<finish> event.
$message->on_finish(sub {
my $self = shift;
say 'Finihsed!';
});
=head2 C<on_progress>
$message->on_progress(sub {...});
Register C<progress> event.
$message->on_progress(sub {
my $self = shift;
say 'Progress!';
});
=head2 C<param>
my $param = $message->param('foo');
Expand Down
16 changes: 8 additions & 8 deletions lib/Mojo/Server.pm
Expand Up @@ -17,7 +17,7 @@ has app_class =>

sub new {
my $self = shift->SUPER::new(@_);
$self->on_request(sub { shift->app->handler(shift) });
$self->on(request => sub { shift->app->handler(shift) });
return $self;
}

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

sub on_request { shift->on(request => shift) }
# DEPRECATED in Smiling Face With Sunglasses!
sub on_request {
warn <<EOF;
Mojo::Server->on_request is DEPRECATED in favor of using Mojo::Server->on!!!
EOF
shift->on(request => shift);
}

# "Are you saying you're never going to eat any animal again? What about
# bacon?
Expand Down Expand Up @@ -147,12 +153,6 @@ Note that this method is EXPERIMENTAL and might change without warning!
say Mojo::Server->new->load_app('./myapp.pl')->home;
=head2 C<on_request>
$server->on_request(sub {...});
Register C<request> event.
=head2 C<run>
$server->run;
Expand Down
2 changes: 1 addition & 1 deletion lib/Mojo/Server/CGI.pm
Expand Up @@ -110,7 +110,7 @@ Mojo::Server::CGI - CGI server
my $cgi = Mojo::Server::CGI->new;
$cgi->unsubscribe_all('request')
$cgi->on_request(sub {
$cgi->on(request => sub {
my ($self, $tx) = @_;
# Request
Expand Down
10 changes: 5 additions & 5 deletions lib/Mojo/Server/Daemon.pm
Expand Up @@ -108,16 +108,16 @@ sub _build_tx {

# Handle
weaken $self;
$tx->on_request(
sub {
$tx->on(
request => sub {
my $tx = pop;
$self->emit(request => $tx);
$tx->on_resume(sub { $self->_write($id) });
$tx->on(resume => sub { $self->_write($id) });
}
);

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

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

# Resume
weaken $self;
$ws->on_resume(sub { $self->_write($id) });
$ws->on(resume => sub { $self->_write($id) });
}

# Failed upgrade
Expand Down
2 changes: 1 addition & 1 deletion lib/Mojo/Server/PSGI.pm
Expand Up @@ -90,7 +90,7 @@ Mojo::Server::PSGI - PSGI server
my $psgi = Mojo::Server::PSGI->new;
$psgi->unsubscribe_all('request');
$psgi->on_request(sub {
$psgi->on(request => sub {
my ($self, $tx) = @_;
# Request
Expand Down
35 changes: 17 additions & 18 deletions lib/Mojo/Transaction.pm
Expand Up @@ -38,8 +38,23 @@ sub is_writing {
return;
}

sub on_finish { shift->on(finish => shift) }
sub on_resume { shift->on(resume => shift) }
# DEPRECATED in Smiling Face With Sunglasses!
sub on_finish {
warn <<EOF;
Mojo::Transaction->on_finish is DEPRECATED in favor of using
Mojo::Transaction->on!!!
EOF
shift->on(finish => shift);
}

# DEPRECATED in Smiling Face With Sunglasses!
sub on_resume {
warn <<EOF;
Mojo::Transaction->on_resume is DEPRECATED in favor of using
Mojo::Transaction->on!!!
EOF
shift->on(resume => shift);
}

sub remote_address {
my ($self, $address) = @_;
Expand Down Expand Up @@ -247,22 +262,6 @@ False.
Check if transaction is writing.
=head2 C<on_finish>
$tx->on_finish(sub {...});
Register C<finish> event.
$tx->on_finish(sub {
my $self = shift;
});
=head2 C<on_resume>
$tx->on_resume(sub {...});
Register C<resume> event.
=head2 C<req>
my $req = $tx->req;
Expand Down
31 changes: 17 additions & 14 deletions lib/Mojo/Transaction/HTTP.pm
Expand Up @@ -173,8 +173,23 @@ sub keep_alive {
return $self->{keep_alive};
}

sub on_request { shift->on(request => shift) }
sub on_upgrade { shift->on(upgrade => shift) }
# DEPRECATED in Smiling Face With Sunglasses!
sub on_request {
warn <<EOF;
Mojo::Transaction::HTTP->on_request is DEPRECATED in favor of using
Mojo::Transaction::HTTP->on!!!
EOF
shift->on(request => shift);
}

# DEPRECATED in Smiling Face With Sunglasses!
sub on_upgrade {
warn <<EOF;
Mojo::Transaction::HTTP->on_upgrade is DEPRECATED in favor of using
Mojo::Transaction::HTTP->on!!!
EOF
shift->on(upgrade => shift);
}

sub server_leftovers {
my $self = shift;
Expand Down Expand Up @@ -458,18 +473,6 @@ Write client data.
Connection can be kept alive.
=head2 C<on_request>
$tx->on_request(sub {...});
Register C<request> event.
=head2 C<on_upgrade>
$tx->on_upgrade(sub {...});
Register C<upgrade> event.
=head2 C<server_leftovers>
my $leftovers = $tx->server_leftovers;
Expand Down
19 changes: 8 additions & 11 deletions lib/Mojo/Transaction/WebSocket.pm
Expand Up @@ -131,7 +131,14 @@ sub is_websocket {1}
sub local_address { shift->handshake->local_address }
sub local_port { shift->handshake->local_port }

sub on_message { shift->on(message => shift) }
# DEPRECATED in Smiling Face With Sunglasses!
sub on_message {
warn <<EOF;
Mojo::Transaction::WebSocket->on_message is DEPRECATED in favor of using
Mojo::Transaction::WebSocket->on!!!
EOF
shift->on(message => shift);
}

sub parse_frame {
my ($self, $buffer) = @_;
Expand Down Expand Up @@ -471,16 +478,6 @@ The local address of this WebSocket.
The local port of this WebSocket.
=head2 C<on_message>
$ws->on_message(sub {...});
Register C<message> event.
$ws->on_message(sub {
my ($self, $message) = @_;
});
=head2 C<parse_frame>
my $frame = $ws->parse_frame(\$bytes);
Expand Down

0 comments on commit 666111f

Please sign in to comment.