| line | stmt | bran | cond | sub | pod | time | code | 
| 1 |  |  |  |  |  |  | package UV::Poll; | 
| 2 |  |  |  |  |  |  |  | 
| 3 |  |  |  |  |  |  | our $VERSION = '1.902'; | 
| 4 |  |  |  |  |  |  |  | 
| 5 | 5 |  |  | 5 |  | 1915 | use strict; | 
|  | 5 |  |  |  |  | 14 |  | 
|  | 5 |  |  |  |  | 154 |  | 
| 6 | 5 |  |  | 5 |  | 29 | use warnings; | 
|  | 5 |  |  |  |  | 6 |  | 
|  | 5 |  |  |  |  | 121 |  | 
| 7 | 5 |  |  | 5 |  | 23 | use Carp (); | 
|  | 5 |  |  |  |  | 7 |  | 
|  | 5 |  |  |  |  | 100 |  | 
| 8 | 5 |  |  | 5 |  | 22 | use Exporter qw(import); | 
|  | 5 |  |  |  |  | 8 |  | 
|  | 5 |  |  |  |  | 155 |  | 
| 9 | 5 |  |  | 5 |  | 1974 | use parent 'UV::Handle'; | 
|  | 5 |  |  |  |  | 1224 |  | 
|  | 5 |  |  |  |  | 26 |  | 
| 10 |  |  |  |  |  |  |  | 
| 11 |  |  |  |  |  |  | our @EXPORT_OK = (@UV::Poll::EXPORT_XS,); | 
| 12 |  |  |  |  |  |  |  | 
| 13 |  |  |  |  |  |  | sub _new_args { | 
| 14 | 3 |  |  | 3 |  | 11 | my ($class, $args) = @_; | 
| 15 | 3 |  |  |  |  | 6 | my ($fd, $is_socket); | 
| 16 | 3 |  |  |  |  | 8 | for my $key (qw(fd fh socket single_arg)) { | 
| 17 | 7 | 100 |  |  |  | 27 | next if !defined($fd = delete $args->{$key}); | 
| 18 |  |  |  |  |  |  |  | 
| 19 | 3 |  |  |  |  | 10 | $is_socket = $key eq "socket"; | 
| 20 | 3 | 50 | 66 |  |  | 22 | if (CORE::ref($fd) eq 'GLOB' || CORE::ref($fd) =~ /^IO::Socket/) { | 
|  |  | 0 | 0 |  |  |  |  | 
| 21 | 3 |  |  |  |  | 23 | $fd = fileno($fd); | 
| 22 | 3 |  |  |  |  | 17 | last; | 
| 23 |  |  |  |  |  |  | } | 
| 24 |  |  |  |  |  |  | elsif (!CORE::ref($fd) && $fd =~ /\A[0-9]+\z/) { | 
| 25 | 0 |  |  |  |  | 0 | last; | 
| 26 |  |  |  |  |  |  | } | 
| 27 |  |  |  |  |  |  | else { | 
| 28 | 0 |  |  |  |  | 0 | $fd = undef; | 
| 29 |  |  |  |  |  |  | } | 
| 30 |  |  |  |  |  |  | } | 
| 31 | 3 | 50 |  |  |  | 9 | unless (defined($fd)) { | 
| 32 | 0 |  |  |  |  | 0 | Carp::croak("No file or socket descriptor provided"); | 
| 33 |  |  |  |  |  |  | } | 
| 34 | 3 |  |  |  |  | 20 | return ($class->SUPER::_new_args($args), $fd, $is_socket); | 
| 35 |  |  |  |  |  |  | } | 
| 36 |  |  |  |  |  |  |  | 
| 37 |  |  |  |  |  |  | sub start { | 
| 38 | 2 |  |  | 2 | 1 | 13 | my $self = shift; | 
| 39 | 2 | 50 |  |  |  | 39 | Carp::croak("Can't start a closed handle") if $self->closed(); | 
| 40 |  |  |  |  |  |  |  | 
| 41 | 2 |  | 50 |  |  | 11 | my $events = shift(@_) || UV::Poll::UV_READABLE; | 
| 42 |  |  |  |  |  |  |  | 
| 43 | 2 | 50 |  |  |  | 5 | if (@_) { | 
| 44 | 0 |  |  |  |  | 0 | $self->on('poll', shift); | 
| 45 |  |  |  |  |  |  | } | 
| 46 | 2 |  |  |  |  | 4 | my $res; | 
| 47 | 2 |  |  |  |  | 4 | my $err = do { #catch | 
| 48 | 2 |  |  |  |  | 3 | local $@; | 
| 49 | 2 |  |  |  |  | 5 | eval { | 
| 50 | 2 |  |  |  |  | 20 | $res = $self->_start($events); | 
| 51 | 2 |  |  |  |  | 6 | 1; | 
| 52 |  |  |  |  |  |  | }; #try | 
| 53 | 2 |  |  |  |  | 7 | $@; | 
| 54 |  |  |  |  |  |  | }; | 
| 55 | 2 | 50 |  |  |  | 7 | Carp::croak($err) if $err; # throw | 
| 56 | 2 |  |  |  |  | 6 | return $res; | 
| 57 |  |  |  |  |  |  | } | 
| 58 |  |  |  |  |  |  |  | 
| 59 |  |  |  |  |  |  | 1; | 
| 60 |  |  |  |  |  |  |  | 
| 61 |  |  |  |  |  |  | __END__ |