summaryrefslogtreecommitdiff
path: root/lib/MON/JSON.pm
diff options
context:
space:
mode:
authorPaul Buetow <paul@buetow.org>2015-01-02 14:00:56 +0100
committerPaul Buetow <paul@buetow.org>2015-01-02 14:00:56 +0100
commit4f27f3ea59baa6cfca0ac1df96b1dfedbd83706c (patch)
tree79754e3c49216f80cb3ad5579851fca0bf1a31c9 /lib/MON/JSON.pm
initial
Diffstat (limited to 'lib/MON/JSON.pm')
-rw-r--r--lib/MON/JSON.pm51
1 files changed, 51 insertions, 0 deletions
diff --git a/lib/MON/JSON.pm b/lib/MON/JSON.pm
new file mode 100644
index 0000000..e12b1ce
--- /dev/null
+++ b/lib/MON/JSON.pm
@@ -0,0 +1,51 @@
+package MON::JSON;
+
+use strict;
+use warnings;
+use v5.10;
+use autodie;
+
+use JSON;
+
+use MON::Display;
+use MON::Utils;
+
+our @ISA = ('MON::Display');
+
+our $JSON_XS = JSON::XS->new();
+
+sub new {
+ my ( $class, %opts ) = @_;
+
+ my $self = bless \%opts, $class;
+
+ $self->init();
+
+ return $self;
+}
+
+sub init {
+ my ($self) = @_;
+
+ return undef;
+}
+
+sub decode {
+ my ( $self, $json ) = @_;
+
+ return $JSON_XS->allow_nonref()->decode($json);
+}
+
+sub encode {
+ my ( $self, $vals ) = @_;
+
+ return $JSON_XS->pretty()->encode($vals);
+}
+
+sub encode_canonical {
+ my ( $self, $vals ) = @_;
+
+ return $JSON_XS->canonical()->pretty()->encode($vals);
+}
+
+1;