line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Dancer2::Serializer::CBOR; |
2
|
|
|
|
|
|
|
# ABSTRACT: CBOR serializer for Dancer2 |
3
|
|
|
|
|
|
|
$Dancer2::Serializer::CBOR::VERSION = '0.000002'; |
4
|
1
|
|
|
1
|
|
72324
|
use Moo; |
|
1
|
|
|
|
|
7968
|
|
|
1
|
|
|
|
|
7
|
|
5
|
1
|
|
|
1
|
|
1476
|
use CBOR::XS (); |
|
1
|
|
|
|
|
2882
|
|
|
1
|
|
|
|
|
91
|
|
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
with 'Dancer2::Core::Role::Serializer'; |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
has '+content_type' => ( default => sub {'application/cbor'} ); |
10
|
|
|
|
|
|
|
|
11
|
0
|
|
|
0
|
0
|
|
sub loaded {1} |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
sub serialize { |
14
|
|
|
|
|
|
|
my ($self, $entity) = @_; |
15
|
|
|
|
|
|
|
CBOR::XS::encode_cbor($entity); |
16
|
|
|
|
|
|
|
} |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
sub deserialize { |
19
|
|
|
|
|
|
|
my ($self, $content) = @_; |
20
|
|
|
|
|
|
|
CBOR::XS::decode_cbor($content); |
21
|
|
|
|
|
|
|
} |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
1; |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
__END__ |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
=pod |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
=encoding UTF-8 |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
=head1 NAME |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
Dancer2::Serializer::CBOR - CBOR serializer for Dancer2 |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
=head1 VERSION |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
version 0.000002 |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
=head1 SYNOPSIS |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
package MyApp::API::CBOR; |
42
|
|
|
|
|
|
|
use Dancer2; |
43
|
|
|
|
|
|
|
set serializer => 'CBOR'; |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
get '/view/user/:id' => sub { |
46
|
|
|
|
|
|
|
my $id = params->{'id'}; |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
return { user => get_id($id) }; |
49
|
|
|
|
|
|
|
}; |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
=head1 DESCRIPTION |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
This serializer allows to serialize and deserialize automatically the CBOR |
54
|
|
|
|
|
|
|
(Concise Binary Object Representation) structure. |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
It requires L<CBOR::XS>. |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
=head1 METHODS |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
=head2 serialize |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
Serialize a Perl data structure to a CBOR structure. |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
=head2 deserialize |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
Deserialize a CBOR structure to a Perl data structure. |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
=head2 content_type |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
C<application/cbor>. |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
=head1 CREDIT |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
The test is based on code David Zurborg has written. |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
=head1 SEE ALSO |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
=over 4 |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
=item * L<CBOR::XS> |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
=item * RFC7049 |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
=back |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
=head1 AUTHOR |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
Sawyer X <xsawyerx@cpan.org> |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
This software is copyright (c) 2014 by Sawyer X. |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
This is free software; you can redistribute it and/or modify it under |
95
|
|
|
|
|
|
|
the same terms as the Perl 5 programming language system itself. |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
=cut |