Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
improved Mojo::IOWatcher exception handling a little
  • Loading branch information
kraih committed Mar 14, 2012
1 parent 03ba3fe commit 78b67b7
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 8 deletions.
3 changes: 2 additions & 1 deletion Changes
@@ -1,6 +1,7 @@
This file documents the revision history for Perl extension Mojolicious.

2.62 2012-03-14 00:00:00
2.62 2012-03-15 00:00:00
- Improved Mojo::IOWatcher exception handling a little.
- Improved documentation.
- Improved tests.

Expand Down
4 changes: 1 addition & 3 deletions lib/Mojo/IOLoop.pm
Expand Up @@ -17,9 +17,7 @@ has client_class => 'Mojo::IOLoop::Client';
has iowatcher => sub {
my $class = Mojo::IOWatcher->detect;
warn "MAINLOOP ($class)\n" if DEBUG;
my $watcher = $class->new;
$watcher->on(error => sub { warn pop });
return $watcher;
return $class->new;
};
has [qw/lock unlock/];
has max_accepts => 0;
Expand Down
6 changes: 4 additions & 2 deletions lib/Mojo/IOWatcher.pm
Expand Up @@ -125,8 +125,10 @@ sub _poll { shift->{poll} ||= IO::Poll->new }

sub _sandbox {
my ($self, $desc, $cb) = (shift, shift, shift);
$self->emit_safe(error => "$desc failed: $@")
unless eval { $self->$cb(@_); 1 };
return if eval { $self->$cb(@_); 1 };
$self->once(error => sub { warn $_[1] })
unless $self->has_subscribers('error');
$self->emit_safe(error => "$desc failed: $@");
}

1;
Expand Down
2 changes: 1 addition & 1 deletion t/mojo/iowatcher.t
Expand Up @@ -164,7 +164,7 @@ is $timer2, 2, 'timer was triggered';

# Error
my $err;
$watcher->unsubscribe('error')->on(
$watcher->on(
error => sub {
shift->stop;
$err = pop;
Expand Down
2 changes: 1 addition & 1 deletion t/mojo/iowatcher_ev.t
Expand Up @@ -165,7 +165,7 @@ is $timer2, 2, 'timer was triggered';

# Error
my $err;
$watcher->unsubscribe('error')->on(
$watcher->on(
error => sub {
shift->stop;
$err = pop;
Expand Down

0 comments on commit 78b67b7

Please sign in to comment.