Skip to content

Commit

Permalink
improved Mojo::IOWatcher backend detection slightly
Browse files Browse the repository at this point in the history
  • Loading branch information
kraih committed Oct 6, 2011
1 parent 100ab31 commit 4c7a242
Show file tree
Hide file tree
Showing 4 changed files with 4 additions and 27 deletions.
1 change: 1 addition & 0 deletions Changes
Expand Up @@ -6,6 +6,7 @@ This file documents the revision history for Perl extension Mojolicious.
- Improved message parser performance slightly.
- Improved Mojo::IOLoop to die if started twice.
- Improved setuidgid in Mojo::Server::Daemon.
- Improved Mojo::IOWatcher backend detection slightly.
- Improved documentation.
- Improved tests.
- Fixed many portability issues.
Expand Down
23 changes: 0 additions & 23 deletions lib/Mojo/IOLoop.pm
Expand Up @@ -36,17 +36,6 @@ has timeout => '0.025';
# Ignore PIPE signal
$SIG{PIPE} = 'IGNORE';

sub new {
my $class = shift;

# Build new loop from singleton and inherit watcher
my $loop = $class->singleton;
my $self = $loop->SUPER::new(@_);
$self->iowatcher($loop->iowatcher->new);

return $self;
}

sub connect {
my $self = shift;
$self = $self->singleton unless ref $self;
Expand Down Expand Up @@ -513,12 +502,8 @@ dropped, defaults to C<3>.
Low level event watcher, usually a L<Mojo::IOWatcher> or
L<Mojo::IOWatcher::EV> object.
Replacing the event watcher of the singleton loop makes all new loops use the
same type of event watcher.
Note that this attribute is EXPERIMENTAL and might change without warning!
Mojo::IOLoop->singleton->iowatcher(MyWatcher->new);
=head2 C<max_accepts>
my $max = $loop->max_accepts;
Expand Down Expand Up @@ -606,14 +591,6 @@ Note that a value of C<0> would make the loop non-blocking.
L<Mojo::IOLoop> inherits all methods from L<Mojo::Base> and implements the
following new ones.
=head2 C<new>
my $loop = Mojo::IOLoop->new;
Construct a new L<Mojo::IOLoop> object.
Multiple of these will block each other, so use C<singleton> instead if
possible.
=head2 C<connect>
my $id = Mojo::IOLoop->connect(
Expand Down
2 changes: 1 addition & 1 deletion lib/Mojo/IOWatcher.pm
Expand Up @@ -33,7 +33,7 @@ sub cancel {

sub detect {
my $try = $ENV{MOJO_IOWATCHER} || 'Mojo::IOWatcher::EV';
return $try if eval "use $try; 1";
return $try if $try->can('new') || eval "use $try; 1";
return 'Mojo::IOWatcher';
}

Expand Down
5 changes: 2 additions & 3 deletions t/mojo/ioloop.t
Expand Up @@ -20,11 +20,10 @@ package MyWatcher;
use Mojo::Base 'Mojo::IOWatcher';

package main;
Mojo::IOLoop->singleton->iowatcher(MyWatcher->new);

# Watcher inheritance
# Watcher detection
$ENV{MOJO_IOWATCHER} = 'MyWatcher';
my $loop = Mojo::IOLoop->new;
Mojo::IOLoop->iowatcher(MyWatcher->new);
is ref $loop->iowatcher, 'MyWatcher', 'right class';

# Double start
Expand Down

0 comments on commit 4c7a242

Please sign in to comment.