File Coverage

blib/lib/AnyEvent/Net/Curl/Queued/Stats.pm
Criterion Covered Total %
statement 22 24 91.6
branch n/a
condition n/a
subroutine 8 8 100.0
pod n/a
total 30 32 93.7


line stmt bran cond sub pod time code
1             package AnyEvent::Net::Curl::Queued::Stats;
2             # ABSTRACT: Connection statistics for AnyEvent::Net::Curl::Queued::Easy
3              
4              
5 4     4   6068 use strict;
  4         9  
  4         142  
6 4     4   22 use utf8;
  4         9  
  4         25  
7 4     4   124 use warnings qw(all);
  4         7  
  4         147  
8              
9 4     4   1559 use AnyEvent;
  4         6740  
  4         136  
10 4     4   26 use Carp qw(confess);
  4         8  
  4         218  
11 4     4   1091 use Moo;
  4         19835  
  4         24  
12 4     4   4058 use MooX::Types::MooseLike::Base qw(HashRef Num);
  4         7400  
  4         326  
13              
14 4     4   853 use AnyEvent::Net::Curl::Const;
  0            
  0            
15              
16             our $VERSION = '0.047'; # VERSION
17              
18              
19             has stamp => (is => 'ro', isa => Num, default => sub { AE::time }, writer => 'set_stamp');
20              
21              
22             has stats => (
23             is => 'ro',
24             isa => HashRef[Num],
25             default => sub { {
26             appconnect_time => 0,
27             connect_time => 0,
28             header_size => 0,
29             namelookup_time => 0,
30             num_connects => 0,
31             pretransfer_time => 0,
32             redirect_count => 0,
33             redirect_time => 0,
34             request_size => 0,
35             size_download => 0,
36             size_upload => 0,
37             starttransfer_time => 0,
38             total_time => 0,
39             } },
40             );
41              
42              
43             sub sum {
44             my ($self, $from) = @_;
45              
46             my $is_stats = (__PACKAGE__ eq ref $from) ? 1 : 0;
47             for my $type (keys %{$self->stats}) {
48             $self->stats->{$type} +=
49             $is_stats
50             ? $from->stats->{$type}
51             : $from->getinfo(AnyEvent::Net::Curl::Const::info($type));
52             }
53              
54             $self->set_stamp(AE::time);
55              
56             return 1;
57             }
58              
59              
60             1;
61              
62             __END__