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.901';
4              
5 39     39   16538 use strict;
  39         134  
  39         1070  
6 39     39   302 use warnings;
  39         69  
  39         956  
7 39     39   345 use Carp ();
  39         75  
  39         790  
8 39     39   230 use Exporter qw(import);
  39         66  
  39         1350  
9 39     39   4893 use UV ();
  39         72  
  39         946  
10 39     39   6117 use UV::Loop ();
  39         77  
  39         15340  
11              
12             sub _new_args {
13 68     68   172 my ($class, $args) = @ _;
14 68   66     531 my $loop = delete $args->{loop} // UV::Loop->default;
15 68         1281 return ($loop);
16             }
17              
18             sub new {
19 68     68 0 22274 my $class = shift;
20 68         294 my %args = @_;
21              
22 68         348 my $self = $class->_new($class->_new_args(\%args));
23 68         327 $self->on(($_ =~ m/^on_(.*)/)[0] => delete $args{$_}) for grep { m/^on_/ } keys %args;
  34         466  
24              
25 68 100       222 if(%args) {
26 7         13 my $code;
27 7   33     150 $code = $self->can("_set_$_") and $self->$code(delete $args{$_}) for keys %args;
28 7 50       34 die "TODO: more args @{[ keys %args ]}" if keys %args;
  0         0  
29             }
30              
31 68         219 return $self;
32             }
33              
34             sub on {
35 85     85 1 9337 my $self = shift;
36 85         243 my $method = "_on_" . shift;
37 85         707 return $self->$method( @_ );
38             }
39              
40             sub close {
41 45     45 1 1095620 my $self = shift;
42 45 100       275 $self->on('close', @_) if @_;
43              
44 45 50 33     641 return if $self->closed || $self->closing;
45 45 100       433 $self->stop if $self->can('stop');
46 45         895 $self->_close;
47             }
48              
49             1;
50              
51             __END__