Skip to content

Commit

Permalink
deprecated all remaining on_* attributes
Browse files Browse the repository at this point in the history
  • Loading branch information
kraih committed Nov 20, 2011
1 parent 89e3f3e commit 12dd053
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 35 deletions.
5 changes: 5 additions & 0 deletions Changes
@@ -1,5 +1,10 @@
This file documents the revision history for Perl extension Mojolicious.

2.30 2011-11-20 00:00:00
- Deprecated Mojo::IOLoop->on_lock in favor of Mojo::IOLoop->lock.
- Deprecated Mojo::IOLoop->on_unlock in favor of
Mojo::IOLoop->unlock.

2.29 2011-11-19 00:00:00
- Deprecated Mojolicious->on_process in favor of around_dispatch
hook.
Expand Down
79 changes: 48 additions & 31 deletions lib/Mojo/IOLoop.pm
Expand Up @@ -20,10 +20,10 @@ has iowatcher => sub {
$class->new;
};
has [qw/cleanup_interval max_accepts/] => 0;
has [qw/lock unlock/];
has max_connections => 1000;
has [qw/on_lock on_unlock/];
has server_class => 'Mojo::IOLoop::Server';
has stream_class => 'Mojo::IOLoop::Stream';
has server_class => 'Mojo::IOLoop::Server';
has stream_class => 'Mojo::IOLoop::Stream';

# Ignore PIPE signal
$SIG{PIPE} = 'IGNORE';
Expand Down Expand Up @@ -220,7 +220,24 @@ sub listen {
# DEPRECATED in Leaf Fluttering In Wind!
sub on_close { shift->_event(close => @_) }
sub on_error { shift->_event(error => @_) }
sub on_read { shift->_event(read => @_) }

# DEPRECATED in Leaf Fluttering In Wind!
sub on_lock {
warn
"Mojo::IOLoop->on_lock is DEPRECATED in favor of Mojo::IOLoop->lock!\n";
shift->lock(@_);
}

# DEPRECATED in Leaf Fluttering In Wind!
sub on_read { shift->_event(read => @_) }

# DEPRECATED in Leaf Fluttering In Wind!
sub on_unlock {
warn <<EOF;
Mojo::IOLoop->on_unlock is DEPRECATED in favor of Mojo::IOLoop->unlock!
EOF
shift->unlock(@_);
}

sub one_tick {
my $self = shift;
Expand Down Expand Up @@ -426,7 +443,7 @@ sub _listening {
my $i = keys %{$self->{connections}};
my $max = $self->max_connections;
return unless $i < $max;
if (my $cb = $self->on_lock) { return unless $self->$cb(!$i) }
if (my $cb = $self->lock) { return unless $self->$cb(!$i) }

# Check if multi-accept is desirable and start listening
$_->accepts($max > 1 ? 10 : 1)->resume for values %$servers;
Expand All @@ -438,7 +455,7 @@ sub _not_listening {

# Check if we are listening
return unless delete $self->{listening};
return unless my $cb = $self->on_unlock;
return unless my $cb = $self->unlock;
$self->$cb();

# Stop listening
Expand Down Expand Up @@ -541,6 +558,23 @@ Note that this attribute is EXPERIMENTAL and might change without warning!
Connection cleanup interval in seconds, defaults to C<0>.
Note that this attribute is EXPERIMENTAL and might change without warning!
=head2 C<lock>
my $cb = $loop->lock;
$loop = $loop->lock(sub {...});
A locking callback that decides if this loop is allowed to accept new
incoming connections, used to sync multiple server processes.
The callback should return true or false.
Note that exceptions in this callback are not captured.
$loop->lock(sub {
my ($loop, $blocking) = @_;
# Got the lock, listen for new connections
return 1;
});
=head2 C<max_accepts>
my $max = $loop->max_accepts;
Expand All @@ -564,31 +598,6 @@ Setting the value to C<0> will make this loop stop accepting new connections
and allow it to shutdown gracefully without interrupting existing
connections.
=head2 C<on_lock>
my $cb = $loop->on_lock;
$loop = $loop->on_lock(sub {...});
A locking callback that decides if this loop is allowed to accept new
incoming connections, used to sync multiple server processes.
The callback should return true or false.
Note that exceptions in this callback are not captured.
$loop->on_lock(sub {
my ($loop, $blocking) = @_;
# Got the lock, listen for new connections
return 1;
});
=head2 C<on_unlock>
my $cb = $loop->on_unlock;
$loop = $loop->on_unlock(sub {...});
A callback to free the accept lock, used to sync multiple server processes.
Note that exceptions in this callback are not captured.
=head2 C<server_class>
my $class = $loop->server_class;
Expand All @@ -607,6 +616,14 @@ Class to be used by C<client> and C<server> methods for I/O streams, defaults
to L<Mojo::IOLoop::Stream>.
Note that this attribute is EXPERIMENTAL and might change without warning!
=head2 C<unlock>
my $cb = $loop->unlock;
$loop = $loop->unlock(sub {...});
A callback to free the accept lock, used to sync multiple server processes.
Note that exceptions in this callback are not captured.
=head1 METHODS
L<Mojo::IOLoop> inherits all methods from L<Mojo::Base> and implements the
Expand Down
4 changes: 2 additions & 2 deletions lib/Mojo/Server/Hypnotoad.pm
Expand Up @@ -345,7 +345,7 @@ sub _spawn {
or croak qq/Can't open lock file "$file": $!/;

# Accept mutex
$loop->on_lock(
$loop->lock(
sub {

# Blocking
Expand All @@ -369,7 +369,7 @@ sub _spawn {
return $l;
}
);
$loop->on_unlock(sub { flock $lock, LOCK_UN });
$loop->unlock(sub { flock $lock, LOCK_UN });

# Heartbeat
weaken $self;
Expand Down
2 changes: 1 addition & 1 deletion lib/Mojolicious.pm
Expand Up @@ -32,7 +32,7 @@ has static => sub { Mojolicious::Static->new };
has types => sub { Mojolicious::Types->new };

our $CODENAME = 'Leaf Fluttering In Wind';
our $VERSION = '2.29';
our $VERSION = '2.30';

# "These old doomsday devices are dangerously unstable.
# I'll rest easier not knowing where they are."
Expand Down
3 changes: 2 additions & 1 deletion t/pod_coverage.t
Expand Up @@ -14,7 +14,8 @@ my @sunglasses = (qw/on_progress on_read on_request on_resume on_start/);
# DEPRECATED in Leaf Fluttering In Wind!
my @leaf = (
qw/add_hook connect connection_timeout is_done listen on_close on_error/,
qw/on_finish on_process on_read run_hook run_hook_reverse write/
qw/on_finish on_lock on_process on_read on_unlock run_hook/,
qw/run_hook_reverse write/
);

# "Marge, I'm going to miss you so much. And it's not just the sex.
Expand Down

0 comments on commit 12dd053

Please sign in to comment.