line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Dancer::Serializer::CBOR; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
15682
|
use strict; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
35
|
|
4
|
1
|
|
|
1
|
|
4
|
use warnings; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
24
|
|
5
|
1
|
|
|
1
|
|
3
|
use Carp; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
72
|
|
6
|
1
|
|
|
1
|
|
230
|
use Dancer::ModuleLoader; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
use Dancer::Exception qw(:all); |
8
|
|
|
|
|
|
|
use base 'Dancer::Serializer::Abstract'; |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
=head1 NAME |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
Dancer::Serializer::CBOR - serializer for handling CBOR data |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
=head1 VERSION |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
Version 0.100 |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
=cut |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
our $VERSION = '0.100'; |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
=head1 SYNOPSIS |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
use Dancer; |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
set serializer => 'CBOR'; |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
get '/view/user/:id' => sub { |
29
|
|
|
|
|
|
|
my $id = params->{'id'}; |
30
|
|
|
|
|
|
|
return { user => get_id($id) }; |
31
|
|
|
|
|
|
|
}; |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
=head1 DESCRIPTION |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
This serializer allows to serialize and deserialize automatically the CBOR (Concise Binary Object Representation) structure. |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
=head1 METHODS |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
=cut |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
# helpers |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
sub loaded { Dancer::ModuleLoader->load('CBOR::XS') } |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
sub init { |
46
|
|
|
|
|
|
|
my ($self) = @_; |
47
|
|
|
|
|
|
|
raise core_serializer => 'CBOR::XS is needed and is not installed' |
48
|
|
|
|
|
|
|
unless $self->loaded; |
49
|
|
|
|
|
|
|
} |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
=head2 serialize |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
Serialize a data structure to a concise binary object representation. |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
=cut |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
sub serialize { |
58
|
|
|
|
|
|
|
my ($self, $entity) = @_; |
59
|
|
|
|
|
|
|
CBOR::XS::encode_cbor($entity); |
60
|
|
|
|
|
|
|
} |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
=head2 deserialize |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
Deserialize a concise binary object representation to a data structure. |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
=cut |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
sub deserialize { |
69
|
|
|
|
|
|
|
my ($self, $content) = @_; |
70
|
|
|
|
|
|
|
CBOR::XS::decode_cbor($content); |
71
|
|
|
|
|
|
|
} |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
=head2 content_type |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
Return 'application/cbor' |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
=cut |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
sub content_type {'application/cbor'} |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
=head1 SEE ALSO |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
=over 4 |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
=item * L |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
=back |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
=head1 AUTHOR |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
David Zurborg, C<< >> |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
=head1 BUGS |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
Please report any bugs or feature requests at L. |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
=head1 SUPPORT |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
You can find documentation for this module with the perldoc command. |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
perldoc Dancer::Serializer::CBOR |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
You can also look for information at: |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
=over 4 |
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
=item * GitHub: Public repository of the module |
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
L |
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
=back |
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
=head1 COPYRIGHT & LICENSE |
114
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
Copyright 2014 David Zurborg, all rights reserved. |
116
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
This program is released under the ISC license. |
118
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
=cut |
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
1; |