File Coverage

blib/lib/Regru/API/Role/Serializer.pm
Criterion Covered Total %
statement 18 18 100.0
branch n/a
condition n/a
subroutine 6 6 100.0
pod n/a
total 24 24 100.0


line stmt bran cond sub pod time code
1              
2             # ABSTRACT: something that can (de)serialize
3              
4             use strict;
5 14     14   21376 use warnings;
  14         30  
  14         337  
6 14     14   58 use Moo::Role;
  14         28  
  14         277  
7 14     14   61 use JSON;
  14         23  
  14         67  
8 14     14   11396 use Carp;
  14         115663  
  14         179  
9 14     14   1732 use namespace::autoclean;
  14         91  
  14         608  
10 14     14   433  
  14         9313  
  14         67  
11             our $VERSION = '0.052'; # VERSION
12             our $AUTHORITY = 'cpan:CHIM'; # AUTHORITY
13              
14             has serializer => (
15             is => 'rw',
16             isa => sub {
17             croak "$_[0] is not a JSON instance" unless ref($_[0]) =~ m/JSON/;
18             croak "$_[0] can not decode" unless $_[0]->can('decode');
19             croak "$_[0] can not encode" unless $_[0]->can('encode');
20             },
21             lazy => 1,
22             default => sub { JSON->new->utf8 },
23             );
24              
25             1; # End of Regru::API::Role::Serializer
26              
27              
28             =pod
29              
30             =encoding UTF-8
31              
32             =head1 NAME
33              
34             Regru::API::Role::Serializer - something that can (de)serialize
35              
36             =head1 VERSION
37              
38             version 0.052
39              
40             =head1 SYNOPSIS
41              
42             package Regru::API::Client;
43             ...
44             with 'Regru::API::Role::Serializer';
45              
46             $str = $self->serializer->encode({ answer => 42, foo => [qw(bar baz quux)] });
47              
48             =head1 DESCRIPTION
49              
50             Any class or role that consumes this one will able to (de)serialize JSON.
51              
52             =head1 ATTRIBUTES
53              
54             =head2 serializer
55              
56             Returns an L<JSON> instance with B<utf8> option enabled.
57              
58             =head1 SEE ALSO
59              
60             L<Regru::API>
61              
62             L<Regru::API::Role::Client>
63              
64             L<JSON>
65              
66             =head1 BUGS
67              
68             Please report any bugs or feature requests on the bugtracker website
69             L<https://github.com/regru/regru-api-perl/issues>
70              
71             When submitting a bug or request, please include a test-file or a
72             patch to an existing test-file that illustrates the bug or desired
73             feature.
74              
75             =head1 AUTHORS
76              
77             =over 4
78              
79             =item *
80              
81             Polina Shubina <shubina@reg.ru>
82              
83             =item *
84              
85             Anton Gerasimov <a.gerasimov@reg.ru>
86              
87             =back
88              
89             =head1 COPYRIGHT AND LICENSE
90              
91             This software is copyright (c) 2013 by REG.RU LLC.
92              
93             This is free software; you can redistribute it and/or modify it under
94             the same terms as the Perl 5 programming language system itself.
95              
96             =cut