Net/Statsd/Server/Backend/Test.pm untested

filter: Statementstmt 0.0% 0 / 29 Branchbran 0.0% 0 / 4 Conditioncond 0.0% 0 / 9 MC/DCmcdc 0.0% 0 / 6 Subroutinesub 0.0% 0 / 5 Podpod 0.0% 0 / 1 totaltotal 0.0% 0 / 54 CC 3 SCAR 18.4
CC
3
Cov
0%
post_stats
12.0
BEGIN
2.0
BEGIN
2.0
CRAP 6.3
1 #
2 # Test statsd backend to write Graphite-like
3 # flushed statistics to a given file.
4 #
5 # To enable this backend, include 'test' in the backends
6 # configuration array:
7 #
8 # "backends": ["test"],
9 #
10 # This backend supports the following config options:
11 #
12 # outputFile: file where to flush statistics (in append mode)
13 #
14  
15 package Net::Statsd::Server::Backend::Test;
16 $Net::Statsd::Server::Backend::Test::VERSION = '0.20';
17 use 5.008;
18 use strict;
19 use warnings;
20 use base qw(Net::Statsd::Server::Backend::Graphite);
21  
22 sub post_stats {
23 my ($self, $stat_list) = @_;
24  
25 my $dump_file = $self->{config}->{outputFile};
26 if (! $dump_file or (-e $dump_file && ! -w $dump_file)) {
27 die "Can't write to dump file '$dump_file': $!";
28 }
29  
30 my $stat_string = $self->stats_to_string($stat_list);
31  
32 eval {
33 open my $dump_fh, '>>', $dump_file;
34 say $dump_fh join(" ", "#", time, "stats flush");
35 say $dump_fh $stat_string;
36 close $dump_fh;
37 $self->{lastFlush} = [Time::HiRes::gettimeofday];
38 }
39 or do {
40 if ($self->{debug}) {
41 # TODO use logger!
42 warn("Exception while posting stats to file $dump_file: $@");
43 }
44 $self->{lastException} = [Time::HiRes::gettimeofday];
45 };
46  
47 }
48  
49 1;