summary refs log tree commit diff
path: root/lib/Net/HTTP/Spore/Middleware
diff options
context:
space:
mode:
authorfranck cuny <franck@lumberjaph.net>2010-10-12 17:18:25 +0200
committerfranck cuny <franck@lumberjaph.net>2010-10-12 17:18:25 +0200
commit85a634ef2e68115636e8a17becbc6a968cab0eae (patch)
tree830bd34674ce8a15bfb6621c89a39a36f0bb2883 /lib/Net/HTTP/Spore/Middleware
parentadd enable_if feature + tests (diff)
downloadnet-http-spore-85a634ef2e68115636e8a17becbc6a968cab0eae.tar.gz
update POD
Diffstat (limited to 'lib/Net/HTTP/Spore/Middleware')
-rw-r--r--lib/Net/HTTP/Spore/Middleware/Auth.pm6
-rw-r--r--lib/Net/HTTP/Spore/Middleware/Format.pm4
-rw-r--r--lib/Net/HTTP/Spore/Middleware/Format/Auto.pm44
3 files changed, 49 insertions, 5 deletions
diff --git a/lib/Net/HTTP/Spore/Middleware/Auth.pm b/lib/Net/HTTP/Spore/Middleware/Auth.pm
index 619215c..0d422a5 100644
--- a/lib/Net/HTTP/Spore/Middleware/Auth.pm
+++ b/lib/Net/HTTP/Spore/Middleware/Auth.pm
@@ -1,5 +1,7 @@
 package Net::HTTP::Spore::Middleware::Auth;
 
+# ABSTRACT: base class for Authentication middlewares
+
 use Moose;
 extends 'Net::HTTP::Spore::Middleware';
 
@@ -8,3 +10,7 @@ sub should_authenticate { $_[1]->env->{'spore.authentication'} }
 sub call { die "should be implemented" }
 
 1;
+
+=head1 DESCRIPTION
+
+Authentication middleware should extends this base class and implement the B<call> method
diff --git a/lib/Net/HTTP/Spore/Middleware/Format.pm b/lib/Net/HTTP/Spore/Middleware/Format.pm
index 559c1e5..2741295 100644
--- a/lib/Net/HTTP/Spore/Middleware/Format.pm
+++ b/lib/Net/HTTP/Spore/Middleware/Format.pm
@@ -83,6 +83,8 @@ If the environment contains a B<payload> (under the name 'spore.payload'), it sh
 
 =head1 METHODS
 
+=over 4
+
 =item serializer_key
 
 name of the extension serializer should check to be sure to not encode a payload already encoded, or set the headers that have already been defined
@@ -116,3 +118,5 @@ this method returns 1 if serialization have not already been done
 this method returns 1 if deserialization have not already been done
 
 =item call
+
+=back
diff --git a/lib/Net/HTTP/Spore/Middleware/Format/Auto.pm b/lib/Net/HTTP/Spore/Middleware/Format/Auto.pm
index fd66b8c..0bc1eb0 100644
--- a/lib/Net/HTTP/Spore/Middleware/Format/Auto.pm
+++ b/lib/Net/HTTP/Spore/Middleware/Format/Auto.pm
@@ -1,17 +1,51 @@
 package Net::HTTP::Spore::Middleware::Format::Auto;
 
 use Moose;
+use MooseX::Types::Moose qw/HashRef Object/;
 extends 'Net::HTTP::Spore::Middleware::Format';
 
+use Try::Tiny;
+
+has seriliazer => (
+    is      => 'rw',
+    isa     => HashRef [Object],
+    lazy    => 1,
+    default => sub { {} },
+);
+
 sub call {
     my ( $self, $req ) = @_;
 
-    $req->env->{'sporex.format'} = 1;
+    my $formats = $req->env->{'spore.format'};
+
+    foreach my $format (@$formats) {
+        my $cls = "Net::HTTP::Spore::Middleware::Format::" . $format;
+        if ( Class::MOP::load($cls) ) {
+            my $s = $cls->new;
+            $self->serializer->{$format} = $s;
+            try {
+                if ( $req->env->{'spore.payload'} ) {
+                    $req->env->{'spore.payload'} =
+                      $s->encode( $req->env->{'spore.payload'} );
+                    $req->header( $s->content_type );
+                }
+                $req->header( $s->accept_type );
+                $req->env->{$self->serializer_key} = 1;
+            };
+            last if $req->env->{$self->serializer_key} == 1;
+        }
+    }
 
-    return $self->response_cb( sub {
-        my $res = shift;
-        return $res;
-    });
+    return $self->response_cb(
+        sub {
+            my $res = shift;
+            return $res;
+        }
+    );
 }
 
 1;
+
+=head1 DESCRIPTION
+
+B<NOT WORKING>