[Bps-public-commit] plient branch, master, updated. 88ef7ee033bf92caaa283f8f5bc500ba9b87aa37

? sunnavy sunnavy at bestpractical.com
Fri Feb 24 01:46:15 EST 2012


The branch, master has been updated
       via  88ef7ee033bf92caaa283f8f5bc500ba9b87aa37 (commit)
       via  107f4d0c90cad32bfc76b76ee7606ee48c0fa554 (commit)
       via  285cfc26383d3fc81f4e17db70dbd12d8d702313 (commit)
       via  ccf9e1124c9a6b635cbc151ccceaed86d38d585a (commit)
       via  e755138890321adc155a39132c237466cd61a537 (commit)
      from  ed15856ddc0ae4702842992eedfc0bc99b1cf26f (commit)

Summary of changes:
 Changes                        |    4 +++
 lib/Plient.pm                  |    2 +-
 lib/Plient/Handler/HTTPLite.pm |    3 +-
 lib/Plient/Handler/HTTPTiny.pm |   38 ++++++++++++++++++++----------------
 lib/Plient/Handler/wget.pm     |    3 +-
 t/http/get.t                   |   41 +++++++++++++++++++++++++++++----------
 t/http/head.t                  |   31 ++++++++++++++++++++++++-----
 t/http/post.t                  |   23 ++++++++++++++++++---
 8 files changed, 104 insertions(+), 41 deletions(-)

- Log -----------------------------------------------------------------
commit e755138890321adc155a39132c237466cd61a537
Author: sunnavy <sunnavy at gmail.com>
Date:   Fri Feb 24 13:56:16 2012 +0800

    update test to skip unusable handlers

diff --git a/t/http/get.t b/t/http/get.t
index 3ec1f79..5826a3a 100644
--- a/t/http/get.t
+++ b/t/http/get.t
@@ -5,21 +5,40 @@ use Test::More tests => 10;
 
 use Plient;
 use Plient::Test;
+use Plient::Util;
+use Plient::Handler::curl;
+use Plient::Handler::wget;
+use Plient::Handler::HTTPLite;
+use Plient::Handler::HTTPTiny;
+use Plient::Handler::LWP;
+$ENV{PLIENT_HANDLER_PREFERENCE_ONLY} = 1;
 
 my $url = start_http_server();
 SKIP: {
     skip 'no plackup available', 10 unless $url;
-    # to test each handler, set env PLIENT_HANDLER_PREFERENCE_ONLY to true
+
     for my $handler (qw/curl wget HTTPLite HTTPTiny LWP/) {
-        Plient->handler_preference( http => [$handler] );
-        is( plient( GET => "$url/hello" ), 'hello', "get /hello using $handler" );
-        is(
-            plient(
-                GET => "$url/hello",
-                { headers => { 'User-Agent' => 'plient/0.01' } }
-            ),
-            'hello plient/0.01',
-            "get /hello using $handler with customized agent"
-        );
+      SKIP: {
+            my $class = 'Plient::Handler::' . $handler;
+            if ( $class->init ) {
+                skip "http_get is not supported in $handler", 2
+                  unless $class->support_method('http_get');
+            }
+            else {
+                skip "$handler not available", 2;
+            }
+
+            Plient->handler_preference( http => [$handler] );
+            is( plient( GET => "$url/hello" ),
+                'hello', "get /hello using $handler" );
+            is(
+                plient(
+                    GET => "$url/hello",
+                    { headers => { 'User-Agent' => 'plient/0.01' } }
+                ),
+                'hello plient/0.01',
+                "get /hello using $handler with customized agent"
+            );
+        }
     }
 }
diff --git a/t/http/head.t b/t/http/head.t
index 60d585d..2054f57 100644
--- a/t/http/head.t
+++ b/t/http/head.t
@@ -1,17 +1,36 @@
 use strict;
 use warnings;
 
-use Test::More tests => 2;
+use Test::More tests => 5;
 
 use Plient;
 use Plient::Test;
+use Plient::Handler::curl;
+use Plient::Handler::wget;
+use Plient::Handler::HTTPLite;
+use Plient::Handler::HTTPTiny;
+use Plient::Handler::LWP;
+$ENV{PLIENT_HANDLER_PREFERENCE_ONLY} = 1;
 
 my $url = start_http_server();
 SKIP: {
-    skip 'no plackup available', 2 unless $url;
-    # to test each handler, set env PLIENT_HANDLER_PREFERENCE_ONLY to true
-    for my $handler (qw/curl wget/) {
-        Plient->handler_preference( http => [$handler] );
-        like( plient( HEAD => "$url/hello" ), qr/Plient-Head-Path: \/hello/, "get head /hello using $handler" );
+    skip 'no plackup available', 5 unless $url;
+    for my $handler (qw/curl wget HTTPLite HTTPTiny LWP/) {
+      SKIP: {
+            my $class = 'Plient::Handler::' . $handler;
+            if ( $class->init ) {
+                skip "http_get is not supported in $handler", 1
+                  unless $class->support_method('http_head');
+            }
+            else {
+                skip "$handler not available", 1;
+            }
+            Plient->handler_preference( http => [$handler] );
+            like(
+                plient( HEAD => "$url/hello" ),
+                qr/Plient-Head-Path: \/hello/,
+                "get head /hello using $handler"
+            );
+        }
     }
 }
diff --git a/t/http/post.t b/t/http/post.t
index 36b07ca..5d016d5 100644
--- a/t/http/post.t
+++ b/t/http/post.t
@@ -5,14 +5,29 @@ use Test::More tests => 5;
 
 use Plient;
 use Plient::Test;
+use Plient::Handler::curl;
+use Plient::Handler::wget;
+use Plient::Handler::HTTPLite;
+use Plient::Handler::HTTPTiny;
+use Plient::Handler::LWP;
+$ENV{PLIENT_HANDLER_PREFERENCE_ONLY} = 1;
 
 my $url = start_http_server();
 SKIP: {
     skip 'no plackup available', 5 unless $url;
-    # to test each handler, set env PLIENT_HANDLER_PREFERENCE_ONLY to true
     for my $handler (qw/curl wget HTTPTiny HTTPLite LWP/) {
-        Plient->handler_preference( http => [$handler] );
-        is( plient( POST => "$url/hello", { body => { name => 'foo' } } ),
-            'hello foo', "post /hello using $handler" );
+      SKIP: {
+            my $class = 'Plient::Handler::' . $handler;
+            if ( $class->init ) {
+                skip "http_get is not supported in $handler", 1
+                  unless $class->support_method('http_post');
+            }
+            else {
+                skip "$handler not available", 1;
+            }
+            Plient->handler_preference( http => [$handler] );
+            is( plient( POST => "$url/hello", { body => { name => 'foo' } } ),
+                'hello foo', "post /hello using $handler" );
+        }
     }
 }

commit ccf9e1124c9a6b635cbc151ccceaed86d38d585a
Author: sunnavy <sunnavy at gmail.com>
Date:   Fri Feb 24 14:17:32 2012 +0800

    shift $class as we need to send @_ to super

diff --git a/lib/Plient/Handler/HTTPLite.pm b/lib/Plient/Handler/HTTPLite.pm
index d3561c2..a830ebf 100644
--- a/lib/Plient/Handler/HTTPLite.pm
+++ b/lib/Plient/Handler/HTTPLite.pm
@@ -12,7 +12,8 @@ sub protocol { return \%protocol }
 sub method { return \%method }
 
 sub support_method {
-    my ( $class, $method, $args ) = @_;
+    my $class = shift;
+    my ( $method, $args ) = @_;
     if (   $args
         && $args->{content_type}
         && $args->{content_type} =~ 'form-data' )
diff --git a/lib/Plient/Handler/HTTPTiny.pm b/lib/Plient/Handler/HTTPTiny.pm
index 858f592..d776404 100644
--- a/lib/Plient/Handler/HTTPTiny.pm
+++ b/lib/Plient/Handler/HTTPTiny.pm
@@ -12,7 +12,8 @@ sub protocol     { return \%protocol }
 sub method       { return \%method }
 
 sub support_method {
-    my ( $class, $method, $args ) = @_;
+    my $class = shift;
+    my ( $method, $args ) = @_;
     if (   $args
         && $args->{content_type}
         && $args->{content_type} =~ 'form-data' )
diff --git a/lib/Plient/Handler/wget.pm b/lib/Plient/Handler/wget.pm
index 552f105..1d8cdbb 100644
--- a/lib/Plient/Handler/wget.pm
+++ b/lib/Plient/Handler/wget.pm
@@ -18,7 +18,8 @@ sub protocol { return \%protocol }
 sub method { return \%method }
 
 sub support_method {
-    my ( $class, $method, $args ) = @_;
+    my $class = shift;
+    my ( $method, $args ) = @_;
     if (   $args
         && $args->{content_type}
         && $args->{content_type} =~ 'form-data' )

commit 285cfc26383d3fc81f4e17db70dbd12d8d702313
Author: sunnavy <sunnavy at gmail.com>
Date:   Fri Feb 24 14:40:24 2012 +0800

    for http_post HTTPTiny, we need to trans content in request call instead, previous code does *not* work

diff --git a/lib/Plient/Handler/HTTPTiny.pm b/lib/Plient/Handler/HTTPTiny.pm
index d776404..a9d0cf9 100644
--- a/lib/Plient/Handler/HTTPTiny.pm
+++ b/lib/Plient/Handler/HTTPTiny.pm
@@ -58,12 +58,29 @@ sub init {
         my $http = HTTP::Tiny->new;
         $http->proxy( $ENV{http_proxy} ) if $ENV{http_proxy};
         add_headers( $http, $uri, $args );
-        add_body( $http, $args->{body_hash} ) if $args->{body_hash};
+
+        my $body;
+        if ( $args->{body_hash} ) {
+            for my $key ( keys %{$args->{body_hash}} ) {
+                # TODO uri escape key and value
+                my $val = $args->{body_hash}{$key};
+                $body .= $body ? "&$key=$val" : "$key=$val";
+            }
+        }
+
         $http->{default_headers}{'Content-Type'} =
           'application/x-www-form-urlencoded'
           unless $http->{default_headers}{'Content-Type'};
 
-        my $res = $http->request( 'POST', $uri );
+        my $res = $http->request(
+            'POST', $uri,
+            {
+                defined $body
+                ? ( content => $body )
+                : ()
+            }
+        );
+
         if ( $res->{success} ) {
             return $res->{content};
         }
@@ -97,20 +114,6 @@ sub add_headers {
     }
 }
 
-sub add_body {
-    my $http = shift;
-    my $hash = shift;
-
-    my $body = '';
-    for my $key ( keys %$hash ) {
-
-        # TODO uri escape key and value
-        my $val = $hash->{$key};
-        $body .= $body ? "&$key=$val" : "$key=$val";
-    }
-    $http->{content} = $body;
-}
-
 __PACKAGE__->_add_to_plient if $Plient::bundle_mode;
 
 1;

commit 107f4d0c90cad32bfc76b76ee7606ee48c0fa554
Author: sunnavy <sunnavy at gmail.com>
Date:   Fri Feb 24 14:43:27 2012 +0800

    word tweak

diff --git a/lib/Plient.pm b/lib/Plient.pm
index 6aca517..7973363 100644
--- a/lib/Plient.pm
+++ b/lib/Plient.pm
@@ -171,7 +171,7 @@ sub _add_handlers {
             $all_handlers{$handler} = ();
         }
         else {
-            warn "$handler doesn't look like a Plient handler";
+            warn "$handler is not a valid Plient handler";
         }
     }
 

commit 88ef7ee033bf92caaa283f8f5bc500ba9b87aa37
Author: sunnavy <sunnavy at gmail.com>
Date:   Fri Feb 24 14:45:50 2012 +0800

    update changes

diff --git a/Changes b/Changes
index ae350e9..f6c8c20 100644
--- a/Changes
+++ b/Changes
@@ -2,6 +2,10 @@ Revision history for Plient
 
 {{$NEXT}}
 
+    updated tests so we can test each handle individually
+    fixed support_method of wget, HTTPLite and HTTPTiny
+    fixed http_post for HTTPTiny
+
 0.02   2011-11-22 11:08:09 CST
 
     test number fix

-----------------------------------------------------------------------



More information about the Bps-public-commit mailing list