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