File Coverage

lib/WebService/LogDNA/Body.pm
Criterion Covered Total %
statement 17 17 100.0
branch n/a
condition n/a
subroutine 6 6 100.0
pod 0 1 0.0
total 23 24 95.8


line stmt bran cond sub pod time code
1             package WebService::LogDNA::Body;
2              
3 2     2   12 use strict;
  2         4  
  2         60  
4 2     2   18 use warnings;
  2         4  
  2         62  
5              
6 2     2   10 use Moo;
  2         4  
  2         18  
7 2     2   784 use Time::HiRes;
  2         4  
  2         14  
8 2     2   1020 use JSON::MaybeXS qw/encode_json/;
  2         11160  
  2         412  
9              
10             has 'line' => (
11             is => 'ro',
12             required => 1,
13             isa => sub {
14             die "Requires a line" unless $_[0] =~ /\S/;
15             }
16             );
17             has 'level' => ( is => 'ro', required => 1 );
18             has 'env' => ( is => 'ro', required => 1 );
19             has 'timestamp' => (
20             is => 'ro',
21             default => sub { int(Time::HiRes::time() * 1000) }
22             );
23             has 'meta' => ( is => 'ro' );
24              
25              
26             sub to_json {
27 1     1 0 4 my( $self ) = @_;
28              
29 1         47 return encode_json({
30             line => $self->line,
31             level => $self->level,
32             env => $self->env,
33             timestamp => $self->timestamp,
34             meta => $self->meta,
35             });
36             }
37              
38             1;
39              
40             __END__