-
Notifications
You must be signed in to change notification settings - Fork 273
/
Dumper.pm
76 lines (46 loc) · 1.17 KB
/
Dumper.pm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# ABSTRACT: TODO
package Dancer::Serializer::Dumper;
use Moo;
use Carp 'croak';
use Data::Dumper;
with 'Dancer::Core::Role::Serializer';
# helpers
sub from_dumper {
my $s = Dancer::Serializer::Dumper->new;
$s->deserialize(@_);
}
sub to_dumper {
my $s = Dancer::Serializer::Dumper->new;
$s->serialize(@_);
}
# class definition
sub BUILD { eval "use Data::Dumper ()"; croak "Fail to load Dumper : $@" if $@ }
sub loaded { 1 }
sub serialize {
my ( $self, $entity ) = @_;
{
local $Data::Dumper::Purity = 1;
return Dumper($entity);
}
}
sub deserialize {
my ( $self, $content ) = @_;
my $res = eval "my \$VAR1; $content";
croak "unable to deserialize : $@" if $@;
return $res;
}
sub content_type {'text/x-data-dumper'}
1;
=head1 NAME
Dancer::Serializer::Dumper - serializer for handling Dumper data
=head1 SYNOPSIS
=head1 DESCRIPTION
Turn Perl data structures into L<Data::Dumper> output and vice-versa.
=head1 METHODS
=head2 serialize
Serialize a Perl data structure into a Dumper string.
=head2 deserialize
Deserialize a Dumper string into a Perl data structure
=head2 content_type
Return 'text/x-data-dumper'
=cut