summary refs log tree commit diff
diff options
context:
space:
mode:
authorfranck cuny <franck@lumberjaph.net>2009-11-24 14:27:17 +0100
committerfranck cuny <franck@lumberjaph.net>2009-11-24 14:27:17 +0100
commit643ed6c86a385bf180a8eeddf5ebdf1a7624dfa5 (patch)
tree89b24b553feabafa900dd2ad37978270bb35e155
parentadd support for (de)serialization (diff)
downloadmoosex-net-api-643ed6c86a385bf180a8eeddf5ebdf1a7624dfa5.tar.gz
move roles to files
-rw-r--r--lib/MooseX/Net/API.pm45
-rw-r--r--lib/MooseX/Net/API/Role/Deserialize.pm21
-rw-r--r--lib/MooseX/Net/API/Role/Serialize.pm21
3 files changed, 46 insertions, 41 deletions
diff --git a/lib/MooseX/Net/API.pm b/lib/MooseX/Net/API.pm
index 14a10f2..b74b85a 100644
--- a/lib/MooseX/Net/API.pm
+++ b/lib/MooseX/Net/API.pm
@@ -95,11 +95,13 @@ sub net_api_method {
                 if $format->{mode} eq 'content-type';
 
             my $res = $self->useragent->request($req);
+            my $content_type = $res->headers->{"content-type"};
+
             if ( $res->is_success ) {
-                my $content_type = $res->headers->{"content-type"};
                 if ( my $type = $reverse_content_type->{$content_type} ) {
                     my $method = '_from_' . $type;
                     return $self->$method( $res->content );
+                }else{
                 }
             }
             else {
@@ -168,47 +170,8 @@ sub new {
 
 }
 
-package MooseX::Net::API::Roles::Deserialize;
-
-use Moose::Role;
-use JSON::XS;
-use YAML::Syck;
-use XML::Simple;
-
-sub _from_json {
-    return decode_json( $_[1] );
-}
-
-sub _from_yaml {
-    return Dump $_[1];
-}
-
-sub _from_xml {
-    my $xml = XML::Simple->new( ForceArray => 0 );
-    $xml->XMLout( { data => $_[0] } );
-}
-
-package MooseX::Net::API::Roles::Serialize;
-
-use Moose::Role;
-use JSON::XS;
-use YAML::Syck;
-use XML::Simple;
-
-sub _to_json {
-    return encode_json( $_[1] );
-}
-
-sub _to_yaml {
-    return Load $_[1];
-}
-
-sub _to_xml {
-    my $xml = XML::Simple->new( ForceArray => 0 );
-    $xml->XMLin("$_[0]");
-}
-
 1;
+
 __END__
 
 =head1 NAME
diff --git a/lib/MooseX/Net/API/Role/Deserialize.pm b/lib/MooseX/Net/API/Role/Deserialize.pm
new file mode 100644
index 0000000..105fb6b
--- /dev/null
+++ b/lib/MooseX/Net/API/Role/Deserialize.pm
@@ -0,0 +1,21 @@
+package MooseX::Net::API::Roles::Deserialize;
+
+use Moose::Role;
+use JSON::XS;
+use YAML::Syck;
+use XML::Simple;
+
+sub _from_json {
+    return decode_json( $_[1] );
+}
+
+sub _from_yaml {
+    return Dump $_[1];
+}
+
+sub _from_xml {
+    my $xml = XML::Simple->new( ForceArray => 0 );
+    $xml->XMLout( { data => $_[0] } );
+}
+
+1;
diff --git a/lib/MooseX/Net/API/Role/Serialize.pm b/lib/MooseX/Net/API/Role/Serialize.pm
new file mode 100644
index 0000000..20e2b97
--- /dev/null
+++ b/lib/MooseX/Net/API/Role/Serialize.pm
@@ -0,0 +1,21 @@
+package MooseX::Net::API::Roles::Serialize;
+
+use Moose::Role;
+use JSON::XS;
+use YAML::Syck;
+use XML::Simple;
+
+sub _to_json {
+    return encode_json( $_[1] );
+}
+
+sub _to_yaml {
+    return Load $_[1];
+}
+
+sub _to_xml {
+    my $xml = XML::Simple->new( ForceArray => 0 );
+    $xml->XMLin("$_[0]");
+}
+
+1;