line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
# ABSTRACT: Serializer for handling Dumper data |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
package Dancer2::Serializer::Dumper; |
4
|
|
|
|
|
|
|
$Dancer2::Serializer::Dumper::VERSION = '1.0.0'; |
5
|
4
|
|
|
4
|
|
67946
|
use Moo; |
|
4
|
|
|
|
|
7405
|
|
|
4
|
|
|
|
|
27
|
|
6
|
4
|
|
|
4
|
|
2770
|
use Carp 'croak'; |
|
4
|
|
|
|
|
25
|
|
|
4
|
|
|
|
|
288
|
|
7
|
4
|
|
|
4
|
|
602
|
use Data::Dumper; |
|
4
|
|
|
|
|
6903
|
|
|
4
|
|
|
|
|
246
|
|
8
|
4
|
|
|
4
|
|
2087
|
use Safe; |
|
4
|
|
|
|
|
150738
|
|
|
4
|
|
|
|
|
1060
|
|
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
with 'Dancer2::Core::Role::Serializer'; |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
has '+content_type' => ( default => sub {'text/x-data-dumper'} ); |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
# helpers |
15
|
2
|
|
|
2
|
1
|
53
|
sub from_dumper { __PACKAGE__->deserialize(@_) } |
16
|
|
|
|
|
|
|
|
17
|
7
|
|
|
7
|
1
|
171
|
sub to_dumper { __PACKAGE__->serialize(@_) } |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
# class definition |
20
|
|
|
|
|
|
|
sub serialize { |
21
|
|
|
|
|
|
|
my ( $self, $entity ) = @_; |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
{ |
24
|
|
|
|
|
|
|
local $Data::Dumper::Purity = 1; |
25
|
|
|
|
|
|
|
return Dumper($entity); |
26
|
|
|
|
|
|
|
} |
27
|
|
|
|
|
|
|
} |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
sub deserialize { |
30
|
|
|
|
|
|
|
my ( $self, $content ) = @_; |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
my $cpt = Safe->new; |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
my $res = $cpt->reval("my \$VAR1; $content"); |
35
|
|
|
|
|
|
|
croak "unable to deserialize : $@" if $@; |
36
|
|
|
|
|
|
|
return $res; |
37
|
|
|
|
|
|
|
} |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
1; |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
__END__ |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
=pod |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
=encoding UTF-8 |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
=head1 NAME |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
Dancer2::Serializer::Dumper - Serializer for handling Dumper data |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
=head1 VERSION |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
version 1.0.0 |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
=head1 DESCRIPTION |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
This is a serializer engine that allows you to turn Perl data structures into |
58
|
|
|
|
|
|
|
L<Data::Dumper> output and vice-versa. |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
=head1 ATTRIBUTES |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
=head2 content_type |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
Returns 'text/x-data-dumper' |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
=head1 METHODS |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
=head2 serialize($content) |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
Serializes a Perl data structure into a Dumper string. |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
=head2 deserialize($content) |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
Deserialize a Dumper string into a Perl data structure. |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
=head1 FUNCTIONS |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
=head2 from_dumper($content) |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
This is an helper available to transform a L<Data::Dumper> output to a Perl |
81
|
|
|
|
|
|
|
data structures. |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
=head2 to_dumper($content) |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
This is an helper available to transform a Perl data structures to a |
86
|
|
|
|
|
|
|
L<Data::Dumper> output. |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
Calling this function will B<not> trigger the serialization's hooks. |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
=head1 AUTHOR |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
Dancer Core Developers |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
This software is copyright (c) 2023 by Alexis Sukrieh. |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
This is free software; you can redistribute it and/or modify it under |
99
|
|
|
|
|
|
|
the same terms as the Perl 5 programming language system itself. |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
=cut |