Net-Statsd-Lite

 view release on metacpan or  search on metacpan

lib/Net/Statsd/Lite.pm  view on Meta::CPAN

package Net::Statsd::Lite;

# ABSTRACT: A StatsD client that supports multimetric packets

use v5.20;

use Moo 1.000000;

use Carp qw/ croak /;
use Devel::StrictMode;
use Digest::SHA 5.96 qw/ hmac_sha256_base64 /;
use IO::Socket::IP;
use MooX::TypeTiny;
use Ref::Util qw/ is_plain_hashref /;
use Scalar::Util qw/ refaddr /;
use Sub::Quote qw/ quote_sub /;
use Sub::Util 1.40 qw/ set_subname /;
use Types::Common 2.000000 qw/ Bool Enum InstanceOf Int IntRange NonEmptySimpleStr
  NumRange PositiveInt PositiveOrZeroInt PositiveOrZeroNum SimpleStr StrMatch Value
  /;

use namespace::autoclean;

use experimental qw/ signatures /;

# RECOMMEND PREREQ: Ref::Util::XS
# RECOMMEND PREREQ: Socket 2.026
# RECOMMEND PREREQ: Type::Tiny::XS

our $VERSION = 'v0.11.2';


has host => (
    is      => 'ro',
    isa     => NonEmptySimpleStr,
    default => '127.0.0.1',
);


has port => (
    is      => 'ro',
    isa     => IntRange[ 0, 65535 ],
    default => 8125,
);


has proto => (
    is      => 'ro',
    isa     => Enum [qw/ tcp udp /],
    default => 'udp',
);


has prefix => (
    is      => 'ro',
    isa     => SimpleStr,
    default => '',
);


has autoflush => (
    is      => 'ro',
    isa     => Bool,
    default => 1,
);

my %Buffers;


has max_buffer_size => (
    is      => 'ro',
    isa     => PositiveInt,
    default => 512,
);


has socket => (
    is      => 'lazy',
    isa     => InstanceOf ['IO::Socket'],
    builder => sub($self) {
        my $sock = IO::Socket::IP->new(
            PeerHost    => $self->host,
            PeerService => $self->port,
            Proto       => $self->proto,
            Type        => SOCK_DGRAM,
        ) or croak "Failed to initialize socket: $!";



( run in 1.325 second using v1.01-cache-2.11-cpan-6aa56a78535 )