From ed4d161fc36a1dfe581439e7da0bb467145f396c Mon Sep 17 00:00:00 2001 From: franck cuny Date: Fri, 27 Nov 2009 10:20:05 +0100 Subject: fix deserialisation --- lib/MooseX/Net/API.pm | 15 +++++++++++++-- lib/MooseX/Net/API/Role/Deserialize.pm | 2 +- 2 files changed, 14 insertions(+), 3 deletions(-) (limited to 'lib') 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; -- cgit 1.4.1