File Coverage

blib/lib/Data/Serializer/JSON/MaybeXS.pm
Criterion Covered Total %
statement 21 21 100.0
branch n/a
condition 2 3 66.6
subroutine 8 8 100.0
pod 2 3 66.6
total 33 35 94.2


line stmt bran cond sub pod time code
1             package Data::Serializer::JSON::MaybeXS;
2              
3             $Data::Serializer::JSON::MaybeXS::VERSION = '0.02';
4              
5 1     1   566 BEGIN { @Data::Serializer::JSON::MaybeXS::ISA = qw(Data::Serializer) }
6              
7             # This code was pretty much stolen and modified from:
8             # Data::Serializer::JSON.
9              
10 1     1   7 use warnings;
  1         2  
  1         25  
11 1     1   4 use strict;
  1         1  
  1         17  
12 1     1   12 use JSON::MaybeXS qw();
  1         2  
  1         18  
13 1     1   4 use vars qw(@ISA);
  1         1  
  1         166  
14              
15             sub json {
16 2     2 0 4 my ($self) = @_;
17              
18             $self->{json} ||= JSON::MaybeXS->new(
19 2   66     12 %{ $self->{options} },
  1         6  
20             );
21              
22 2         35 return $self->{json};
23             }
24              
25             sub serialize {
26 1     1 1 34 my ($self, $data) = @_;
27 1         2 return $self->json->encode( $data );
28             }
29              
30             sub deserialize {
31 1     1 1 14 my ($self, $json) = @_;
32 1         2 return $self->json->decode( $json );
33             }
34              
35             1;
36             __END__