| line | stmt | bran | cond | sub | pod | time | code | 
| 1 |  |  |  |  |  |  | package UV::Loop; | 
| 2 |  |  |  |  |  |  |  | 
| 3 |  |  |  |  |  |  | our $VERSION = '1.902'; | 
| 4 |  |  |  |  |  |  |  | 
| 5 | 42 |  |  | 42 |  | 129745 | use strict; | 
|  | 42 |  |  |  |  | 207 |  | 
|  | 42 |  |  |  |  | 1305 |  | 
| 6 | 42 |  |  | 42 |  | 235 | use warnings; | 
|  | 42 |  |  |  |  | 98 |  | 
|  | 42 |  |  |  |  | 969 |  | 
| 7 |  |  |  |  |  |  |  | 
| 8 | 42 |  |  | 42 |  | 206 | use Carp (); | 
|  | 42 |  |  |  |  | 78 |  | 
|  | 42 |  |  |  |  | 752 |  | 
| 9 | 42 |  |  | 42 |  | 203 | use Exporter qw(import); | 
|  | 42 |  |  |  |  | 80 |  | 
|  | 42 |  |  |  |  | 1636 |  | 
| 10 | 42 |  |  | 42 |  | 358 | use Scalar::Util (); | 
|  | 42 |  |  |  |  | 87 |  | 
|  | 42 |  |  |  |  | 817 |  | 
| 11 | 42 |  |  | 42 |  | 9546 | use UV (); | 
|  | 42 |  |  |  |  | 88 |  | 
|  | 42 |  |  |  |  | 1658 |  | 
| 12 |  |  |  |  |  |  |  | 
| 13 | 42 |  |  | 42 |  | 301 | use constant DEBUG => $ENV{PERL_UV_DEBUG}; | 
|  | 42 |  |  |  |  | 72 |  | 
|  | 42 |  |  |  |  | 26717 |  | 
| 14 |  |  |  |  |  |  |  | 
| 15 |  |  |  |  |  |  | our @EXPORT_OK = (@UV::Loop::EXPORT_XS,); | 
| 16 |  |  |  |  |  |  | my $default_loop; | 
| 17 |  |  |  |  |  |  |  | 
| 18 |  |  |  |  |  |  | # simple function to ensure we've been given a UV::Loop | 
| 19 |  |  |  |  |  |  | # this is useful in new Handle construction | 
| 20 |  |  |  |  |  |  | sub _is_a_loop { | 
| 21 | 0 |  |  | 0 |  | 0 | my $loop = shift; | 
| 22 | 0 | 0 |  |  |  | 0 | return undef unless $loop; | 
| 23 | 0 | 0 | 0 |  |  | 0 | return undef unless ref($loop) && Scalar::Util::blessed($loop); | 
| 24 | 0 | 0 |  |  |  | 0 | return undef unless $loop->isa('UV::Loop'); | 
| 25 | 0 |  |  |  |  | 0 | return 1; | 
| 26 |  |  |  |  |  |  | } | 
| 27 |  |  |  |  |  |  |  | 
| 28 |  |  |  |  |  |  | sub new { | 
| 29 | 30 |  |  | 30 | 1 | 686 | my $class = shift; | 
| 30 | 30 |  |  |  |  | 52 | print STDERR "UV::Loop->new() called\n" if DEBUG; | 
| 31 | 30 |  |  |  |  | 122 | my $args = UV::_parse_args(@_); | 
| 32 |  |  |  |  |  |  |  | 
| 33 | 30 |  | 100 |  |  | 3265 | my $self = $class->_new($args->{_default} // 0); | 
| 34 |  |  |  |  |  |  |  | 
| 35 | 30 |  |  |  |  | 261 | $self->on('walk', $args->{on_walk}); | 
| 36 | 30 |  |  |  |  | 87 | print STDERR "UV::Loop->new() walk callback added\n" if DEBUG; | 
| 37 |  |  |  |  |  |  |  | 
| 38 | 30 |  |  |  |  | 52 | print STDERR "UV::Loop->new() done\n" if DEBUG; | 
| 39 | 30 |  |  |  |  | 95 | return $self; | 
| 40 |  |  |  |  |  |  | } | 
| 41 |  |  |  |  |  |  |  | 
| 42 |  |  |  |  |  |  | # Return the singleton uv_default_loop | 
| 43 |  |  |  |  |  |  | sub default { | 
| 44 | 1694 |  |  | 1694 | 1 | 515238 | print STDERR "loop default() singleton called\n" if DEBUG; | 
| 45 | 1694 |  |  |  |  | 2688 | my $class = shift; | 
| 46 | 1694 | 100 |  |  |  | 3473 | if (defined($default_loop)) { | 
| 47 | 1668 |  |  |  |  | 2024 | print STDERR "loop default() returning already stored default loop\n" if DEBUG; | 
| 48 | 1668 |  |  |  |  | 125231 | return $default_loop; | 
| 49 |  |  |  |  |  |  | } | 
| 50 | 26 |  |  |  |  | 50 | print STDERR "loop default() We don't have a default. Let's create one!\n" if DEBUG; | 
| 51 | 26 |  |  |  |  | 105 | $default_loop = $class->new(@_, _default => 1); | 
| 52 | 26 |  |  |  |  | 43 | print STDERR "loop default() returning newly created and stored default loop\n" if DEBUG; | 
| 53 | 26 |  |  |  |  | 192 | return $default_loop; | 
| 54 |  |  |  |  |  |  | } | 
| 55 |  |  |  |  |  |  |  | 
| 56 | 1 |  |  | 1 | 1 | 721 | sub default_loop { return shift->default(); } | 
| 57 |  |  |  |  |  |  |  | 
| 58 |  |  |  |  |  |  | sub on { | 
| 59 | 35 |  |  | 35 | 1 | 72 | my $self = shift; | 
| 60 | 35 |  |  |  |  | 149 | my $method = "_on_" . shift; | 
| 61 | 35 |  |  |  |  | 293 | return $self->$method( @_ ); | 
| 62 |  |  |  |  |  |  | } | 
| 63 |  |  |  |  |  |  |  | 
| 64 |  |  |  |  |  |  | sub walk { | 
| 65 | 10 |  |  | 10 | 1 | 500574 | my $self = shift; | 
| 66 | 10 | 100 |  |  |  | 67 | return unless $self->alive(); | 
| 67 | 5 | 50 |  |  |  | 19 | $self->on('walk', @_) if @_; # set the callback ahead of time if exists | 
| 68 | 5 |  |  |  |  | 83 | $self->_walk(); | 
| 69 |  |  |  |  |  |  | } | 
| 70 |  |  |  |  |  |  |  | 
| 71 |  |  |  |  |  |  | sub getaddrinfo { | 
| 72 | 2 |  |  | 2 | 1 | 5017 | my $self = shift; | 
| 73 | 2 |  |  |  |  | 5 | my ($args, $cb) = @_; | 
| 74 |  |  |  |  |  |  |  | 
| 75 | 2 |  |  |  |  | 5 | $self->_getaddrinfo(@{$args}{qw( node service flags family socktype protocol )}, $cb); | 
|  | 2 |  |  |  |  | 504 |  | 
| 76 |  |  |  |  |  |  | } | 
| 77 |  |  |  |  |  |  |  | 
| 78 |  |  |  |  |  |  | 1; | 
| 79 |  |  |  |  |  |  |  | 
| 80 |  |  |  |  |  |  | __END__ |