AnyEvent-Net-Curl-Queued

 view release on metacpan or  search on metacpan

lib/AnyEvent/Net/Curl/Queued/Stats.pm  view on Meta::CPAN

package AnyEvent::Net::Curl::Queued::Stats;
# ABSTRACT: Connection statistics for AnyEvent::Net::Curl::Queued::Easy


use strict;
use utf8;
use warnings qw(all);

use AnyEvent;
use Carp qw(confess);
use Moo;
use MooX::Types::MooseLike::Base qw(HashRef Num);

use AnyEvent::Net::Curl::Const;

our $VERSION = '0.049'; # VERSION


has stamp       => (is => 'ro', isa => Num, default => sub { AE::time }, writer => 'set_stamp');


has stats       => (
    is          => 'ro',
    isa         => HashRef[Num],
    default     => sub { {
        appconnect_time     => 0,
        connect_time        => 0,
        header_size         => 0,
        namelookup_time     => 0,
        num_connects        => 0,
        pretransfer_time    => 0,
        redirect_count      => 0,
        redirect_time       => 0,
        request_size        => 0,
        size_download       => 0,
        size_upload         => 0,
        starttransfer_time  => 0,
        total_time          => 0,
    } },
);


sub sum {
    my ($self, $from) = @_;

    my $is_stats = (__PACKAGE__ eq ref $from) ? 1 : 0;
    for my $type (keys %{$self->stats}) {
        $self->stats->{$type} +=
            $is_stats
                ? $from->stats->{$type}
                : $from->getinfo(AnyEvent::Net::Curl::Const::info($type));
    }

    $self->set_stamp(AE::time);

    return 1;
}


1;

__END__

=pod

=encoding UTF-8



( run in 0.741 second using v1.01-cache-2.11-cpan-39bf76dae61 )