From af59204a30f9beb83c2a47a0a3692cbfa3873398 Mon Sep 17 00:00:00 2001 From: franck cuny Date: Wed, 15 Sep 2010 18:16:25 +0200 Subject: pod --- lib/Net/HTTP/Spore/Middleware/Format.pm | 6 ++++++ lib/Net/HTTP/Spore/Middleware/Format/JSON.pm | 15 +++++++++++++ lib/Net/HTTP/Spore/Middleware/Format/XML.pm | 15 +++++++++++++ lib/Net/HTTP/Spore/Middleware/Format/YAML.pm | 16 ++++++++++++++ lib/Net/HTTP/Spore/Middleware/LogDispatch.pm | 32 ++++++++++++++++++++++++++++ 5 files changed, 84 insertions(+) (limited to 'lib/Net') 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 header in your request. If the request method is PUT or POST, the B 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 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 header in your request. If the request method is PUT or POST, the B 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 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 header in your request. If the request method is PUT or POST, the B 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 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 -- cgit 1.4.1