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.902';
4              
5 39     39   17610 use strict;
  39         94  
  39         1108  
6 39     39   314 use warnings;
  39         68  
  39         990  
7 39     39   297 use Carp ();
  39         80  
  39         893  
8 39     39   257 use Exporter qw(import);
  39         70  
  39         1483  
9 39     39   6164 use UV ();
  39         86  
  39         963  
10 39     39   7413 use UV::Loop ();
  39         84  
  39         16075  
11              
12             sub _new_args {
13 68     68   167 my ($class, $args) = @ _;
14 68   66     450 my $loop = delete $args->{loop} // UV::Loop->default;
15 68         1294 return ($loop);
16             }
17              
18             sub new {
19 68     68 0 22710 my $class = shift;
20 68         240 my %args = @_;
21              
22 68         309 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         387  
24              
25 68 100       215 if(%args) {
26 7         10 my $code;
27 7   33     103 $code = $self->can("_set_$_") and $self->$code(delete $args{$_}) for keys %args;
28 7 50       28 die "TODO: more args @{[ keys %args ]}" if keys %args;
  0         0  
29             }
30              
31 68         211 return $self;
32             }
33              
34             sub on {
35 85     85 1 9982 my $self = shift;
36 85         247 my $method = "_on_" . shift;
37 85         736 return $self->$method( @_ );
38             }
39              
40             sub close {
41 45     45 1 1101875 my $self = shift;
42 45 100       264 $self->on('close', @_) if @_;
43              
44 45 50 33     643 return if $self->closed || $self->closing;
45 45 100       466 $self->stop if $self->can('stop');
46 45         955 $self->_close;
47             }
48              
49             1;
50              
51             __END__