summary refs log tree commit diff
diff options
context:
space:
mode:
authorfranck cuny <franck@lumberjaph.net>2009-11-27 10:20:05 +0100
committerfranck cuny <franck@lumberjaph.net>2009-11-27 10:20:05 +0100
commited4d161fc36a1dfe581439e7da0bb467145f396c (patch)
tree29047020c9202911883967643f81ed6cd6d05cbb
parentnew tests (diff)
downloadmoosex-net-api-ed4d161fc36a1dfe581439e7da0bb467145f396c.tar.gz
fix deserialisation
-rw-r--r--lib/MooseX/Net/API.pm15
-rw-r--r--lib/MooseX/Net/API/Role/Deserialize.pm2
2 files changed, 14 insertions, 3 deletions
diff --git a/lib/MooseX/Net/API.pm b/lib/MooseX/Net/API.pm
index 49ba0c7..e1ab774 100644
--- a/lib/MooseX/Net/API.pm
+++ b/lib/MooseX/Net/API.pm
@@ -1,6 +1,8 @@
 package MooseX::Net::API;
 
 use Carp;
+use URI;
+use HTTP::Request;
 use Try::Tiny;
 use Moose::Exporter;
 use MooseX::Net::API::Error;
@@ -17,7 +19,8 @@ my $list_content_type = {
 my $reverse_content_type = {
     'application/json'   => 'json',
     'application/x-yaml' => 'yaml',
-    'text/xml'           => 'xml'
+    'text/xml'           => 'xml',
+    'application/xml'    => 'xml',
 };
 
 # XXX uri builder
@@ -209,6 +212,7 @@ sub net_api_method {
 
             my $res          = $self->useragent->request($req);
             my $content_type = $res->headers->{"content-type"};
+            $content_type =~ s/(;.+)$//;
 
             my @deserialize_order
                 = ( $content_type, $format, keys %$list_content_type );
@@ -286,7 +290,14 @@ sub _do_deserialization {
 
     my $content;
     foreach my $deserializer (@content_types) {
-        my $method = '_from_' . $deserializer;
+        my $method;
+        if ( $reverse_content_type->{$deserializer} ) {
+            $method = '_from_' . $reverse_content_type->{$deserializer};
+        }
+        else {
+            $method = '_from_' . $deserializer;
+        }
+        next if ( !$caller->meta->find_method_by_name($method) );
         try {
             $content = $caller->$method($raw_content);
         };
diff --git a/lib/MooseX/Net/API/Role/Deserialize.pm b/lib/MooseX/Net/API/Role/Deserialize.pm
index 577af21..b83c58a 100644
--- a/lib/MooseX/Net/API/Role/Deserialize.pm
+++ b/lib/MooseX/Net/API/Role/Deserialize.pm
@@ -15,7 +15,7 @@ sub _from_yaml {
 
 sub _from_xml {
     my $xml = XML::Simple->new( ForceArray => 0 );
-    $xml->XMLout( { data => $_[0] } );
+    $xml->XMLin( $_[1] );
 }
 
 1;