File Coverage

blib/lib/UV/Loop.pm
Criterion Covered Total %
statement 50 55 90.9
branch 5 12 41.6
condition 2 5 40.0
subroutine 13 14 92.8
pod 6 6 100.0
total 76 92 82.6


line stmt bran cond sub pod time code
1             package UV::Loop;
2              
3             our $VERSION = '1.900';
4              
5 42     42   125600 use strict;
  42         217  
  42         1273  
6 42     42   223 use warnings;
  42         74  
  42         969  
7              
8 42     42   251 use Carp ();
  42         64  
  42         768  
9 42     42   182 use Exporter qw(import);
  42         72  
  42         1643  
10 42     42   332 use Scalar::Util ();
  42         91  
  42         748  
11 42     42   9431 use UV ();
  42         154  
  42         1623  
12              
13 42     42   296 use constant DEBUG => $ENV{PERL_UV_DEBUG};
  42         73  
  42         26581  
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 649 my $class = shift;
30 30         51 print STDERR "UV::Loop->new() called\n" if DEBUG;
31 30         119 my $args = UV::_parse_args(@_);
32              
33 30   100     2868 my $self = $class->_new($args->{_default} // 0);
34              
35 30         321 $self->on('walk', $args->{on_walk});
36 30         83 print STDERR "UV::Loop->new() walk callback added\n" if DEBUG;
37              
38 30         53 print STDERR "UV::Loop->new() done\n" if DEBUG;
39 30         104 return $self;
40             }
41              
42             # Return the singleton uv_default_loop
43             sub default {
44 1706     1706 1 514279 print STDERR "loop default() singleton called\n" if DEBUG;
45 1706         2560 my $class = shift;
46 1706 100       3300 if (defined($default_loop)) {
47 1680         1878 print STDERR "loop default() returning already stored default loop\n" if DEBUG;
48 1680         124886 return $default_loop;
49             }
50 26         46 print STDERR "loop default() We don't have a default. Let's create one!\n" if DEBUG;
51 26         112 $default_loop = $class->new(@_, _default => 1);
52 26         48 print STDERR "loop default() returning newly created and stored default loop\n" if DEBUG;
53 26         209 return $default_loop;
54             }
55              
56 1     1 1 728 sub default_loop { return shift->default(); }
57              
58             sub on {
59 35     35 1 77 my $self = shift;
60 35         109 my $method = "_on_" . shift;
61 35         275 return $self->$method( @_ );
62             }
63              
64             sub walk {
65 10     10 1 500207 my $self = shift;
66 10 100       68 return unless $self->alive();
67 5 50       22 $self->on('walk', @_) if @_; # set the callback ahead of time if exists
68 5         198 $self->_walk();
69             }
70              
71             sub getaddrinfo {
72 2     2 1 5061 my $self = shift;
73 2         5 my ($args, $cb) = @_;
74              
75 2         4 $self->_getaddrinfo(@{$args}{qw( node service flags family socktype protocol )}, $cb);
  2         473  
76             }
77              
78             1;
79              
80             __END__