File Coverage

blib/lib/Riemann/Client.pm
Criterion Covered Total %
statement 12 26 46.1
branch 0 8 0.0
condition n/a
subroutine 4 7 57.1
pod 2 2 100.0
total 18 43 41.8


line stmt bran cond sub pod time code
1             package Riemann::Client;
2             $Riemann::Client::VERSION = '0.04';
3 2     2   287541 use Moo;
  2         26549  
  2         14  
4 2     2   4127 use Net::Domain qw/hostfqdn/;
  2         4444  
  2         125  
5              
6 2     2   876 use Riemann::Client::Transport::TCP;
  2         10  
  2         82  
7 2     2   974 use Riemann::Client::Transport::UDP;
  2         7  
  2         652  
8              
9             has host => (is => 'ro', default => sub { 'localhost' });
10             has port => (is => 'ro', default => sub { 5555 } );
11             has proto => (is => 'rwp', default => sub { 'tcp' } );
12              
13             has transport => (is => 'rwp', lazy => 1, builder => 1);
14              
15             sub send {
16 0     0 1   my ($self, @opts) = @_;
17              
18             # Set default stuff
19             map {
20 0 0         $_->{host} = hostfqdn() unless defined $_->{host};
  0            
21 0 0         $_->{time} = time() unless defined $_->{time};
22 0 0         $_->{metric_d} = delete $_->{metric} if $_->{metric};
23             } @opts;
24              
25 0           return $self->transport->send({events => \@opts});
26             }
27              
28             sub query {
29 0     0 1   my ($self, $query) = @_;
30              
31 0 0         if (ref $self->transport eq 'Riemann::Client::Transport::UDP') {
32 0           $self->_set_proto('tcp');
33 0           $self->_set_transport($self->_build_transport);
34             }
35              
36 0           return $self->transport->send({
37             query => { string => $query }
38             });
39             }
40              
41             sub _build_transport {
42 0     0     my $self = shift;
43 0           my $class = 'Riemann::Client::Transport::' . uc $self->proto;
44 0           return $class->new(
45             host => $self->host,
46             port => $self->port,
47             );
48             }
49              
50             1;
51              
52             __END__