about summary refs log tree commit diff
diff options
context:
space:
mode:
authorfranck cuny <franck@lumberjaph.net>2010-12-08 17:30:19 +0100
committerfranck cuny <franck@lumberjaph.net>2010-12-08 17:30:19 +0100
commit6acef1a1d19aa37a92406934db40883e1796bea5 (patch)
treefb2aeb51ba14dc5925d13646af673aced628b8f8
parentallow format_options (diff)
downloadnet-http-api-6acef1a1d19aa37a92406934db40883e1796bea5.tar.gz
pass the format optiosn to the serializers
-rw-r--r--lib/Net/HTTP/API/Parser/JSON.pm11
-rw-r--r--lib/Net/HTTP/API/Role/Format.pm9
-rw-r--r--lib/Net/HTTP/API/Role/Serialization.pm2
3 files changed, 12 insertions, 10 deletions
diff --git a/lib/Net/HTTP/API/Parser/JSON.pm b/lib/Net/HTTP/API/Parser/JSON.pm
index 2edc71c..d340c75 100644
--- a/lib/Net/HTTP/API/Parser/JSON.pm
+++ b/lib/Net/HTTP/API/Parser/JSON.pm
@@ -6,21 +6,14 @@ use JSON;
 use Moose;
 extends 'Net::HTTP::API::Parser';
 
-has _json_parser => (
-    is      => 'rw',
-    isa     => 'JSON',
-    lazy    => 1,
-    default => sub { JSON->new->allow_nonref },
-);
-
 sub encode {
     my ($self, $content) = @_;
-    $self->_json_parser->encode($content);
+    JSON::to_json($content, $self->format_options);
 }
 
 sub decode {
     my ($self, $content) = @_;
-    $self->_json_parser->decode($content);
+    JSON::from_json($content, $self->format_options);
 }
 
 1;
diff --git a/lib/Net/HTTP/API/Role/Format.pm b/lib/Net/HTTP/API/Role/Format.pm
index 1d8c10f..5e19543 100644
--- a/lib/Net/HTTP/API/Role/Format.pm
+++ b/lib/Net/HTTP/API/Role/Format.pm
@@ -19,6 +19,15 @@ subtype Format => as 'Str' => where {
 
 enum 'FormatMode' => qw(content-type append);
 
+has api_format_options => (
+    is      => 'rw',
+    isa     => 'HashRef',
+    default => sub {
+        my $self = shift;
+        $self->meta->get_api_option('api_format_options');
+    }
+);
+
 has api_format => (
     is      => 'rw',
     isa     => 'Format',
diff --git a/lib/Net/HTTP/API/Role/Serialization.pm b/lib/Net/HTTP/API/Role/Serialization.pm
index ee98800..dc719a9 100644
--- a/lib/Net/HTTP/API/Role/Serialization.pm
+++ b/lib/Net/HTTP/API/Role/Serialization.pm
@@ -69,7 +69,7 @@ sub _load_serializer {
     my $format = shift || $self->api_format;
     my $parser = "Net::HTTP::API::Parser::" . uc($format);
     if (Class::MOP::load_class($parser)) {
-        my $o = $parser->new;
+        my $o = $parser->new(format_options => $self->api_format_options);
         $self->_add_serializer($format => $o);
         return $o;
     }