File Coverage

blib/lib/UV/Handle.pm
Criterion Covered Total %
statement 39 40 97.5
branch 8 10 80.0
condition 4 9 44.4
subroutine 10 10 100.0
pod 2 3 66.6
total 63 72 87.5


line stmt bran cond sub pod time code
1             package UV::Handle;
2              
3             our $VERSION = '1.900';
4              
5 39     39   17380 use strict;
  39         112  
  39         1140  
6 39     39   344 use warnings;
  39         69  
  39         1011  
7 39     39   307 use Carp ();
  39         86  
  39         861  
8 39     39   233 use Exporter qw(import);
  39         94  
  39         1389  
9 39     39   5735 use UV ();
  39         73  
  39         971  
10 39     39   6765 use UV::Loop ();
  39         85  
  39         16068  
11              
12             sub _new_args {
13 68     68   201 my ($class, $args) = @ _;
14 68   66     463 my $loop = delete $args->{loop} // UV::Loop->default;
15 68         1280 return ($loop);
16             }
17              
18             sub new {
19 68     68 0 22235 my $class = shift;
20 68         247 my %args = @_;
21              
22 68         320 my $self = $class->_new($class->_new_args(\%args));
23 68         315 $self->on(($_ =~ m/^on_(.*)/)[0] => delete $args{$_}) for grep { m/^on_/ } keys %args;
  34         394  
24              
25 68 100       217 if(%args) {
26 7         12 my $code;
27 7   33     95 $code = $self->can("_set_$_") and $self->$code(delete $args{$_}) for keys %args;
28 7 50       24 die "TODO: more args @{[ keys %args ]}" if keys %args;
  0         0  
29             }
30              
31 68         246 return $self;
32             }
33              
34             sub on {
35 85     85 1 9110 my $self = shift;
36 85         246 my $method = "_on_" . shift;
37 85         724 return $self->$method( @_ );
38             }
39              
40             sub close {
41 45     45 1 1096868 my $self = shift;
42 45 100       300 $self->on('close', @_) if @_;
43              
44 45 50 33     646 return if $self->closed || $self->closing;
45 45 100       444 $self->stop if $self->can('stop');
46 45         977 $self->_close;
47             }
48              
49             1;
50              
51             __END__