File Coverage

blib/lib/App/AutoCRUD/View/Json.pm
Criterion Covered Total %
statement 16 16 100.0
branch n/a
condition n/a
subroutine 5 5 100.0
pod 0 1 0.0
total 21 22 95.4


line stmt bran cond sub pod time code
1             package App::AutoCRUD::View::Json;
2              
3 1     1   467 use 5.010;
  1         2  
4 1     1   4 use Moose;
  1         2  
  1         7  
5             extends 'App::AutoCRUD::View';
6              
7 1     1   4149 use JSON::MaybeXS;
  1         1  
  1         67  
8 1     1   4 use namespace::clean -except => 'meta';
  1         2  
  1         7  
9              
10             has 'json_args' => ( is => 'bare', isa => 'HashRef',
11             default => sub {{ pretty => 1,
12             allow_blessed => 1,
13             convert_blessed => 1 }} );
14              
15              
16             sub render {
17 2     2 0 3 my ($self, $data, $context) = @_;
18              
19             # encode output
20 2         4 my $json_maker = JSON::MaybeXS->new(%{$self->{json_args}});
  2         16  
21 2         75 my $output = $json_maker->encode($data);
22              
23 2         77 return [200, ['Content-type' => 'application/json; charset=UTF-8'],
24             [$output] ];
25             }
26              
27             1;
28              
29              
30             __END__
31              
32              
33