File Coverage

blib/lib/HTTP/Throwable/Role/JSONBody.pm
Criterion Covered Total %
statement 13 15 86.6
branch n/a
condition n/a
subroutine 5 6 83.3
pod 0 3 0.0
total 18 24 75.0


line stmt bran cond sub pod time code
1             package HTTP::Throwable::Role::JSONBody;
2             # ABSTRACT - JSON Body
3             $HTTP::Throwable::Role::JSONBody::VERSION = '0.001';
4 1     1   10147 use Moo::Role;
  1         2  
  1         4  
5 1     1   562 use JSON::MaybeXS;
  1         824  
  1         118  
6              
7             has payload => (
8             is => 'ro',
9             required => 1,
10             );
11              
12             sub body {
13 1     1 0 3583 my $self = shift;
14              
15 1         17 return encode_json($self->payload);
16             }
17              
18             sub body_headers {
19 1     1 0 6 my ($self, $body) = @_;
20              
21             return [
22 1         4 'Content-Type' => 'application/json',
23             'Content-Length' => length $body,
24             ];
25             }
26              
27             sub as_string {
28 0     0 0   my $self = shift;
29              
30 0           return $self->body;
31             }
32              
33 1     1   5 no Moo::Role; 1;
  1         1  
  1         5  
34              
35             =pod
36              
37             =encoding UTF-8
38              
39             =head1 NAME
40              
41             HTTP::Throwable::Role::JSONBody
42              
43             =head1 VERSION
44              
45             version 0.001
46              
47             =head1 OVERVIEW
48              
49             This role does two things - accepts a C argument that should be
50             anything you can pass to L, and then encodes it as the
51             body, specifying a C of C.
52              
53             =head1 AUTHOR
54              
55             Matthew Horsfall
56              
57             =head1 COPYRIGHT AND LICENSE
58              
59             This software is copyright (c) 2016 by Matthew Horsfall.
60              
61             This is free software; you can redistribute it and/or modify it under
62             the same terms as the Perl 5 programming language system itself.
63              
64             =cut
65              
66             __END__