Graphite.pm

filter: Statementstmt 47.2% 17 / 36 Branchbran 0.0% 0 / 4 Conditioncond 0.0% 0 / 10 MC/DCmcdc 0.0% 0 / 6 Subroutinesub 50.0% 5 / 10 Podpod 0.0% 0 / 3 totaltotal 31.8% 22 / 69 CC 7 SCAR 25.1
CC
7
Cov
34%
send
30.0
new
12.0
__ANON__
2.0
CRAP 12.3
« Graphite/SNMPAgent.pm ↑ Summary
1 package AnyEvent::Graphite;
2  
3 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 1 our $VERSION = '0.08';
7  
8 1 ▶use AnyEvent;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 1 ▶use AnyEvent::Socket;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 1 ▶use AnyEvent::Handle;
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 0 ▶sub new {
Subroutine new: not called CC=3 SCAR=24.8
Pod undocumented
13 0 my($class, %args) = @_;
14  
15 # the rest of the args will get passed to the object
16 # so remove host and port as we'll possibly set them manually here
17 0 ▶ my $host = delete $args{host} || '127.0.0.1';
Condition0%0/2
delete $args{'host'} || '127.0.0.1'
l!l
00
MC/DC0%0/1
delete $args{'host'} || '127.0.0.1'
delete $args{'host'}
Truth table0%0/2
A
A= delete $args{'host'}
Aresult
11
00
18 0 ▶ my $port = delete $args{port} || 2003;
Condition0%0/2
delete $args{'port'} || 2003
l!l
00
MC/DC0%0/1
delete $args{'port'} || 2003
delete $args{'port'}
Truth table0%0/2
A
A= delete $args{'port'}
Aresult
11
00
19  
20 0 bless {
21 host => $host,
22 port => $port,
23 %args,
24 }, $class;
25 }
26  
27 0 ▶sub send {
Subroutine send: not called CC=5 SCAR=34.0
Pod undocumented
28 0 my($self, $id, $value, $ts) = @_;
29 0 ▶ return unless (defined($id) && defined($value));
Branch: 1 branch
BranchTrueFalseTotal
unless defined $id and defined $value 0 0 0
Condition0%0/3
defined $id and defined $value
!ll&&!rl&&r
000
MC/DC0%0/2
defined $id and defined $value
defined $id defined $value
Truth table0%0/3
A and B
A= defined $idB= defined $value
ABresult
0X0
100
111
30 0 ▶ $ts ||= AE::now; # cached time() from the framework
Condition0%0/3
$ts ||= &AE::now()
l!l&&r!l&&!r
000
MC/DC0%0/2
$ts ||= &AE::now()
$ts &AE::now()
Truth table0%0/3
A ||= B
A= $tsB= &AE::now()
ABresult
1X1
011
000
31 0 ▶ if($self->{conn}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{'conn'}) { } 0 0 0
32 0 $self->{conn}->push_write(join(" ", $id, $value, $ts) . "\n");
33 } else {
34 0 my $handle; $handle = new AnyEvent::Handle
35 connect => [$self->{host} => $self->{port}],
36 0 ▶ on_error => sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
37 # we have no reason to exist w/out a connection.
38 0 die "Unable to connect to Graphite server at $self->{host}:$self->{port}: $!\n";
39 0 };
40 0 $self->{conn} = $handle;
41 0 $self->send($id, $value, $ts);
42 }
43 }
44  
45 0 ▶sub finish {
Subroutine finish: not called CC=1 SCAR=6.9
Pod undocumented
46 # you need to let the client actually process the data, so the event loop needs to run
47 # this lets you let your data get out, but still exit when it's done
48 0 my($self) = @_;
49 0 ▶ $self->{conn}->on_drain(sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
50 0 print "All data transmitted\n";
51 0 exit;
52 0 });
53 0 AnyEvent->condvar->recv;
54 }
55  
56 =head1 NAME
57  
58 AnyEvent::Graphite - A non-blocking Graphite (http://graphite.wikidot.com/) client
59  
60 =head1 VERSION
61  
62 Version 0.08
63  
64 =head1 SYNOPSIS
65  
66 my $graphite = AnyEvent::Graphite->new(
67 host => '127.0.0.1',
68 port => '2003',
69 );
70 $graphite->send("a.b.c.d", $value, $timestamp); #timestamp is optional
71  
72 =head1 AUTHOR
73  
74 Joshua Barratt, C<< <josh at mediatemple.net> >>
75  
76 =head1 COPYRIGHT & LICENSE
77  
78 This program is free software; you can redistribute it and/or modify it
79 under the same terms as Perl itself.
80  
81 =cut
82  
83 1 1; # End of AnyEvent::Graphite
« Graphite/SNMPAgent.pm ↑ Summary