File Coverage

blib/lib/Kelp/Module/JSON/XS.pm
Criterion Covered Total %
statement 16 16 100.0
branch n/a
condition n/a
subroutine 5 5 100.0
pod 1 3 33.3
total 22 24 91.6


line stmt bran cond sub pod time code
1             package Kelp::Module::JSON::XS;
2 1     1   561884 use Kelp::Base 'Kelp::Module::Encoder';
  1         2  
  1         8  
3 1     1   3451 use JSON::XS;
  1         7459  
  1         331  
4              
5             our $VERSION = '0.503';
6              
7 3     3 0 117098 sub encoder_name { 'json' }
8              
9             sub build_encoder {
10 2     2 0 126 my ($self, $args) = @_;
11 2         32 my $json = JSON::XS->new;
12              
13 2         5 for my $key (keys %{$args}) {
  2         8  
14 6         32 $json->$key($args->{$key});
15             }
16              
17 2         57 return $json;
18             }
19              
20             sub build {
21 1     1 1 141 my ( $self, %args ) = @_;
22 1         8 $self->SUPER::build(%args);
23              
24 1         6 $self->register(json => $self->get_encoder);
25             }
26              
27             1;
28              
29             __END__
30              
31             =head1 NAME
32              
33             Kelp::Module::JSON::XS - DEPRECATED JSON:XS module for Kelp applications
34              
35             =head1 DEPRECATED
36              
37             B<*** This module is now deprecated. ***>
38              
39             Kelp is now using L<JSON::MaybeXS>, which will automatically choose the most
40             fitting backend for JSON.
41              
42             Kelp used L<JSON> module before that. Beginning with version 2.0 of the JSON
43             module, when both JSON and JSON::XS are installed, then JSON will fall back on
44             JSON::XS
45              
46             =head1 SYNOPSIS
47              
48             package MyApp;
49             use Kelp::Base 'Kelp';
50              
51             sub some_route {
52             my $self = shift;
53             return $self->json->encode( { success => \1 } );
54             }
55              
56             =head1 REGISTERED METHODS
57              
58             This module registers only one method into the application: C<json>.
59              
60             =head2 CONFIGURATION
61              
62             In C<conf/config.pl>:
63              
64             {
65             modules => ['JSON:XS'], # And whatever else you need
66             modules_init => {
67             'JSON::XS' => {
68             pretty => 1,
69             allow_blessed => 1
70             # And whetever else you want
71             }
72             }
73             }
74              
75             =head2 AUTHOR
76              
77             Stefan Geneshky minimal@cpan.org
78              
79             =head2 LICENCE
80              
81             Perl
82              
83             =cut
84