| 1 | package Zing::Encoder::Json; | ||
| 2 | |||
| 3 | use 5.014; | ||
| 4 | |||
| 5 | use strict; | ||
| 6 | use warnings; | ||
| 7 | |||
| 8 | use registry 'Zing::Types'; | ||
| 9 | use routines; | ||
| 10 | |||
| 11 | use Data::Object::Class; | ||
| 12 | |||
| 13 | extends 'Zing::Encoder'; | ||
| 14 | |||
| 15 | use JSON -convert_blessed_universally; | ||
| 16 | |||
| 17 | our $VERSION = '0.01'; # VERSION | ||
| 18 | |||
| 19 | # METHODS | ||
| 20 | |||
| 21 | method decode(Str $data) { | ||
| 22 | return JSON->new->allow_nonref->convert_blessed->decode($data); | ||
| 23 | } | ||
| 24 | |||
| 25 | method encode(HashRef $data) { | ||
| 26 | return JSON->new->allow_nonref->convert_blessed->encode($data); | ||
| 27 | } | ||
| 28 | |||
| 29 | 1; | ||
| 30 | |||
| 31 | =encoding utf8 | ||
| 32 | |||
| 33 | =head1 NAME | ||
| 34 | |||
| 35 | Zing::Encoder::Json - JSON Serialization Abstraction | ||
| 36 | |||
| 37 | =cut | ||
| 38 | |||
| 39 | =head1 ABSTRACT | ||
| 40 | |||
| 41 | JSON Data Serialization Abstraction | ||
| 42 | |||
| 43 | =cut | ||
| 44 | |||
| 45 | =head1 SYNOPSIS | ||
| 46 | |||
| 47 | use Zing::Encoder::Json; | ||
| 48 | |||
| 49 | my $encoder = Zing::Encoder::Json->new; | ||
| 50 | |||
| 51 | # $encoder->encode({ status => 'okay' }); | ||
| 52 | |||
| 53 | =cut | ||
| 54 | |||
| 55 | =head1 DESCRIPTION | ||
| 56 | |||
| 57 | This package provides a L<JSON> data serialization abstraction for use with | ||
| 58 | L<Zing::Store> stores. | ||
| 59 | |||
| 60 | =cut | ||
| 61 | |||
| 62 | =head1 LIBRARIES | ||
| 63 | |||
| 64 | This package uses type constraints from: | ||
| 65 | |||
| 66 | L<Zing::Types> | ||
| 67 | |||
| 68 | =cut | ||
| 69 | |||
| 70 | =head1 METHODS | ||
| 71 | |||
| 72 | This package implements the following methods: | ||
| 73 | |||
| 74 | =cut | ||
| 75 | |||
| 76 | =head2 decode | ||
| 77 | |||
| 78 | decode(Str $data) : HashRef | ||
| 79 | |||
| 80 | The decode method decodes the data provided. | ||
| 81 | |||
| 82 | =over 4 | ||
| 83 | |||
| 84 | =item decode example #1 | ||
| 85 | |||
| 86 | # given: synopsis | ||
| 87 | |||
| 88 | $encoder->decode('{ "status":"okay" }'); | ||
| 89 | |||
| 90 | =back | ||
| 91 | |||
| 92 | =cut | ||
| 93 | |||
| 94 | =head2 encode | ||
| 95 | |||
| 96 | encode(HashRef $data) : Str | ||
| 97 | |||
| 98 | The encode method encodes the data provided. | ||
| 99 | |||
| 100 | =over 4 | ||
| 101 | |||
| 102 | =item encode example #1 | ||
| 103 | |||
| 104 | # given: synopsis | ||
| 105 | |||
| 106 | $encoder->encode({ status => 'okay' }); | ||
| 107 | |||
| 108 | =back | ||
| 109 | |||
| 110 | =cut | ||
| 111 | |||
| 112 | =head1 AUTHOR | ||
| 113 | |||
| 114 | Al Newkirk, C<awncorp@cpan.org> | ||
| 115 | |||
| 116 | =head1 LICENSE | ||
| 117 | |||
| 118 | Copyright (C) 2011-2019, Al Newkirk, et al. | ||
| 119 | |||
| 120 | This is free software; you can redistribute it and/or modify it under the terms | ||
| 121 | of the The Apache License, Version 2.0, as elucidated in the L<"license | ||
| 122 | file"|https://github.com/iamalnewkirk/zing-encoder-json/blob/master/LICENSE>. | ||
| 123 | |||
| 124 | =head1 PROJECT | ||
| 125 | |||
| 126 | L<Wiki|https://github.com/iamalnewkirk/zing-encoder-json/wiki> | ||
| 127 | |||
| 128 | L<Project|https://github.com/iamalnewkirk/zing-encoder-json> | ||
| 129 | |||
| 130 | L<Initiatives|https://github.com/iamalnewkirk/zing-encoder-json/projects> | ||
| 131 | |||
| 132 | L<Milestones|https://github.com/iamalnewkirk/zing-encoder-json/milestones> | ||
| 133 | |||
| 134 | L<Contributing|https://github.com/iamalnewkirk/zing-encoder-json/blob/master/CONTRIBUTE.md> | ||
| 135 | |||
| 136 | L<Issues|https://github.com/iamalnewkirk/zing-encoder-json/issues> | ||
| 137 | |||
| 138 | =cut |