File Coverage

blib/lib/Dancer2/Serializer/JsonApi.pm
Criterion Covered Total %
statement 11 11 100.0
branch n/a
condition n/a
subroutine 4 4 100.0
pod n/a
total 15 15 100.0


line stmt bran cond sub pod time code
1 4     4   443211 use 5.38.0;
  4         19  
2              
3              
4             package Dancer2::Serializer::JsonApi;
5             our $AUTHORITY = 'cpan:YANICK';
6             $Dancer2::Serializer::JsonApi::VERSION = '0.0.1';
7 4     4   1085 use Dancer2::Plugin::JsonApi::Registry;
  4         12  
  4         181  
8 4     4   2764 use Dancer2::Serializer::JSON;
  4         917343  
  4         175  
9              
10 4     4   36 use Moo;
  4         12  
  4         23  
11              
12              
13             has content_type => ( is => 'ro', default => 'application/vnd.api+json' );
14              
15             with 'Dancer2::Core::Role::Serializer';
16              
17              
18             has registry => (
19             is => 'rw',
20             default => sub { Dancer2::Plugin::JsonApi::Registry->new }
21             );
22              
23              
24             has json_serializer => (
25             is => 'ro',
26             default => sub { Dancer2::Serializer::JSON->new }
27             );
28              
29              
30             sub serialize {
31             my ( $self, $data ) = @_;
32              
33             return $self->json_serializer->serialize(
34             $self->registry->serialize(@$data) );
35             }
36              
37              
38             sub deserialize ( $self, $serialized, @ ) {
39             $self->registry->deserialize(
40             $self->json_serializer->deserialize($serialized) );
41             }
42              
43             1;
44              
45             __END__