diff options
author | franck cuny <franck@lumberjaph.net> | 2010-09-15 18:16:25 +0200 |
---|---|---|
committer | franck cuny <franck@lumberjaph.net> | 2010-09-15 18:16:25 +0200 |
commit | af59204a30f9beb83c2a47a0a3692cbfa3873398 (patch) | |
tree | 00e829ed8c26f80260c6ecc5288b00dcd727a300 | |
parent | auth format remove proto (diff) | |
download | net-http-spore-af59204a30f9beb83c2a47a0a3692cbfa3873398.tar.gz |
pod
-rw-r--r-- | lib/Net/HTTP/Spore/Middleware/Format.pm | 6 | ||||
-rw-r--r-- | lib/Net/HTTP/Spore/Middleware/Format/JSON.pm | 15 | ||||
-rw-r--r-- | lib/Net/HTTP/Spore/Middleware/Format/XML.pm | 15 | ||||
-rw-r--r-- | lib/Net/HTTP/Spore/Middleware/Format/YAML.pm | 16 | ||||
-rw-r--r-- | lib/Net/HTTP/Spore/Middleware/LogDispatch.pm | 32 |
5 files changed, 84 insertions, 0 deletions
diff --git a/lib/Net/HTTP/Spore/Middleware/Format.pm b/lib/Net/HTTP/Spore/Middleware/Format.pm index 7acd376..10fc457 100644 --- a/lib/Net/HTTP/Spore/Middleware/Format.pm +++ b/lib/Net/HTTP/Spore/Middleware/Format.pm @@ -1,5 +1,7 @@ package Net::HTTP::Spore::Middleware::Format; +# ABSTRACT: base class for formats middlewares + use Moose; extends 'Net::HTTP::Spore::Middleware'; @@ -8,6 +10,9 @@ sub decode { die "must be implemented" } sub accept_type { die "must be implemented" } sub content_type { die "must be implemented" } +# sporex.(de)serialization +# spore.format : list supported formats + sub call { my ( $self, $req ) = @_; @@ -35,3 +40,4 @@ sub call { } 1; + diff --git a/lib/Net/HTTP/Spore/Middleware/Format/JSON.pm b/lib/Net/HTTP/Spore/Middleware/Format/JSON.pm index 61326cd..3fe54de 100644 --- a/lib/Net/HTTP/Spore/Middleware/Format/JSON.pm +++ b/lib/Net/HTTP/Spore/Middleware/Format/JSON.pm @@ -1,5 +1,7 @@ package Net::HTTP::Spore::Middleware::Format::JSON; +# ABSTRACT: middleware for JSON format + use JSON; use Moose; extends 'Net::HTTP::Spore::Middleware::Format'; @@ -17,3 +19,16 @@ sub accept_type { ( 'Accept' => 'application/json' ) } sub content_type { ( 'Content-Type' => 'application/json' ) } 1; + +=head1 SYNOPSIS + + my $client = Net::HTTP::Spore->new_from_spec('twitter.json'); + $client->enable('Format::JSON'); + +=head1 DESCRIPTION + +Net::HTTP::Spore::Middleware::Format::JSON is a simple middleware to handle the JSON format. It will set the appropriate B<Accept> header in your request. If the request method is PUT or POST, the B<Content-Type> header will also be set to JSON. + +This middleware will also deserialize content in the response. The deserialized content will be store in the B<body> of the response. + +=head1 EXAMPLES diff --git a/lib/Net/HTTP/Spore/Middleware/Format/XML.pm b/lib/Net/HTTP/Spore/Middleware/Format/XML.pm index c4ae038..a5a5743 100644 --- a/lib/Net/HTTP/Spore/Middleware/Format/XML.pm +++ b/lib/Net/HTTP/Spore/Middleware/Format/XML.pm @@ -1,5 +1,7 @@ package Net::HTTP::Spore::Middleware::Format::XML; +# ABSTRACT: middleware for XML format + use Moose; extends 'Net::HTTP::Spore::Middleware::Format'; @@ -11,3 +13,16 @@ sub encode { XMLout( $_[1] ) } sub decode { XMLin( $_[1] ) } 1; + +=head1 SYNOPSIS + + my $client = Net::HTTP::Spore->new_from_spec('twitter.json'); + $client->enable('Format::XML'); + +=head1 DESCRIPTION + +Net::HTTP::Spore::Middleware::Format::XML is a simple middleware to handle the XML format. It will set the appropriate B<Accept> header in your request. If the request method is PUT or POST, the B<Content-Type> header will also be set to XML. + +This middleware will also deserialize content in the response. The deserialized content will be store in the B<body> of the response. + +=head1 EXAMPLES diff --git a/lib/Net/HTTP/Spore/Middleware/Format/YAML.pm b/lib/Net/HTTP/Spore/Middleware/Format/YAML.pm index bd844ce..6dca86c 100644 --- a/lib/Net/HTTP/Spore/Middleware/Format/YAML.pm +++ b/lib/Net/HTTP/Spore/Middleware/Format/YAML.pm @@ -1,5 +1,7 @@ package Net::HTTP::Spore::Middleware::Format::YAML; +# ABSTRACT: middleware for YAML format + use YAML; use Moose; extends 'Net::HTTP::Spore::Middleware::Format'; @@ -10,3 +12,17 @@ sub accept_type { ( 'Accept' => 'text/x-yaml' ) } sub content_type { ( 'Content-Type' => 'text/x-yaml' ) } 1; + +=head1 SYNOPSIS + + my $client = Net::HTTP::Spore->new_from_spec('github.json'); + $client->enable('Format::YAML'); + +=head1 DESCRIPTION + +Net::HTTP::Spore::Middleware::Format::YAML is a simple middleware to handle the YAML format. It will set the appropriate B<Accept> header in your request. If the request method is PUT or POST, the B<Content-Type> header will also be set to YAML. + +This middleware will also deserialize content in the response. The deserialized content will be store in the B<body> of the response. + +=head1 EXAMPLES + diff --git a/lib/Net/HTTP/Spore/Middleware/LogDispatch.pm b/lib/Net/HTTP/Spore/Middleware/LogDispatch.pm index 2724fcf..422c76d 100644 --- a/lib/Net/HTTP/Spore/Middleware/LogDispatch.pm +++ b/lib/Net/HTTP/Spore/Middleware/LogDispatch.pm @@ -3,5 +3,37 @@ package Net::HTTP::Spore::Middleware::LogDispatch; use Moose; extends 'Net::HTTP::Spore::Middleware'; +has logger => (is => 'rw', isa => 'Log::Dispatch', required => 1); + +sub call { + my ($self, $req) = @_; + + my $env = $req->env; + $env->{'sporex.logger'} = sub { + my $args = shift; + $args->{level} = 'critical' if $args->{level} eq 'fatal'; + $self->logger->log(%$args); + }; +} 1; + +=head1 SYNOPSIS + + my $log = Log::Dispatch->new(); + $log->add( + Log::Dispatch::File->new( + name => 'file1', + min_level => 'debug', + filename => 'logfile' + ) + ); + + my $client = Net::HTTP::Spore->new_from_spec('twitter.json'); + $client->enable( 'LogDispatch', logger => $log ); + +=head1 DESCRIPTION + +Net::HTTP::Spore::Middleware::LogDispatch is a middleware that allow you to use LogDispatch. + +=head1 EXAMPLES |