line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package MojoX::AIO; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
37652
|
use strict; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
42
|
|
4
|
1
|
|
|
1
|
|
5
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
48
|
|
5
|
|
|
|
|
|
|
|
6
|
1
|
|
|
1
|
|
514
|
use Mojo::Base -base; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
use Mojo::IOLoop; |
9
|
|
|
|
|
|
|
use IO::AIO qw( poll_fileno poll_cb ); |
10
|
|
|
|
|
|
|
use Carp qw( croak ); |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
has 'ioloop' => sub { Mojo::IOLoop->singleton }; |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
our $VERSION = '0.06'; |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
our $singleton; |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
sub import { |
19
|
|
|
|
|
|
|
my ( $class, $args ) = @_; |
20
|
|
|
|
|
|
|
my $package = caller(); |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
croak "MojoX::AIO expects its arguments in a hash ref" |
23
|
|
|
|
|
|
|
if ( $args && ref( $args ) ne 'HASH' ); |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
unless ( delete $args->{no_auto_export} ) { |
26
|
|
|
|
|
|
|
eval( "package $package; use IO::AIO qw( 2 );" ); |
27
|
|
|
|
|
|
|
if ( $@ ) { |
28
|
|
|
|
|
|
|
croak "could not export IO::AIO into $package (is it installed?)"; |
29
|
|
|
|
|
|
|
} |
30
|
|
|
|
|
|
|
} |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
return if ( $args->{no_auto_bootstrap} ); |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
# bootstrap |
35
|
|
|
|
|
|
|
$class->new( %$args ); |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
return; |
38
|
|
|
|
|
|
|
} |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
sub new { |
41
|
|
|
|
|
|
|
my $class = shift; |
42
|
|
|
|
|
|
|
return $singleton if ( $singleton ); |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
my $self = $singleton = bless({ @_ }, ref $class || $class ); |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
open(my $fh, '<&=', poll_fileno) |
47
|
|
|
|
|
|
|
or croak "Can't open IO::AIO poll_fileno: $!"; |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
my $stream = Mojo::IOLoop::Stream->new($fh); |
50
|
|
|
|
|
|
|
$stream->on(read => \&poll_cb); |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
$self->ioloop->stream($stream); |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
return $self; |
55
|
|
|
|
|
|
|
} |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
sub singleton() { |
58
|
|
|
|
|
|
|
return $singleton; |
59
|
|
|
|
|
|
|
} |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
1; |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
__END__ |