[Bps-public-commit] plient branch, master, updated. 0b47a64fc376cbe360f944753f8cbe6ec7e8210d

? sunnavy sunnavy at bestpractical.com
Tue Apr 20 09:37:48 EDT 2010


The branch, master has been updated
       via  0b47a64fc376cbe360f944753f8cbe6ec7e8210d (commit)
       via  0ce8a56c46841f373cb9e09988a70aec64f504ce (commit)
       via  5a422bd8a0701e995c3cfa7caa4b562287de59a1 (commit)
       via  5508de8dc44e314698ce9b25789a0f43bb4f5da7 (commit)
       via  0fdf4f513574696a3d5525a10f5bd76d774a1993 (commit)
       via  ec9262207825d32cd601edc914ed9f4cadba6a1d (commit)
      from  e5b146c5a063693e62a2a88a77cfc855ad40faa5 (commit)

Summary of changes:
 lib/Plient.pm                  |    2 +-
 lib/Plient/Handler/HTTPLite.pm |   16 ++++++++++++++++
 lib/Plient/Handler/LWP.pm      |   17 +++++++++++++++++
 lib/Plient/Handler/curl.pm     |    7 ++++++-
 lib/Plient/Handler/wget.pm     |    9 ++++++++-
 t/http/get.t                   |    8 ++++++--
 t/http/post.t                  |   10 +++++++---
 7 files changed, 61 insertions(+), 8 deletions(-)

- Log -----------------------------------------------------------------
commit ec9262207825d32cd601edc914ed9f4cadba6a1d
Author: sunnavy <sunnavy at bestpractical.com>
Date:   Tue Apr 20 21:04:19 2010 +0800

    add PLIENT_HANDLER_PREFERENCE_ONLY env to we can specify the exact handlers, no more handlers if this is true

diff --git a/lib/Plient.pm b/lib/Plient.pm
index e4168c1..8ab9b65 100644
--- a/lib/Plient.pm
+++ b/lib/Plient.pm
@@ -80,7 +80,7 @@ sub handlers {
                   : delete $map{"Plient::Handler::$_"}
               } @$preference;
         }
-        push @handlers, keys %map;
+        push @handlers, keys %map unless $ENV{PLIENT_HANDLER_PREFERENCE_ONLY};
         return @handlers;
     }
     else {

commit 0fdf4f513574696a3d5525a10f5bd76d774a1993
Author: sunnavy <sunnavy at bestpractical.com>
Date:   Tue Apr 20 21:06:07 2010 +0800

    use PLIENT_HANDLER_PREFERENCE_ONLY to test each handler

diff --git a/t/http/get.t b/t/http/get.t
index 3e1457e..5b3e6d5 100644
--- a/t/http/get.t
+++ b/t/http/get.t
@@ -1,7 +1,7 @@
 use strict;
 use warnings;
 
-use Test::More tests => 3;
+use Test::More tests => 6;
 
 use_ok('Plient');
 use_ok('Plient::Test');
@@ -9,5 +9,9 @@ use_ok('Plient::Test');
 my $url = start_http_server();
 SKIP: {
     skip 'no plackup available', 1 unless $url;
-    is( plient( GET => "$url/hello" ), 'hello', 'get /hello' );
+    # to test each handler, set env PLIENT_HANDLER_PREFERENCE_ONLY to true
+    for my $handler (qw/curl wget HTTPLite LWP/) {
+        Plient->handler_preference( http => [$handler] );
+        is( plient( GET => "$url/hello" ), 'hello', 'get /hello' );
+    }
 }
diff --git a/t/http/post.t b/t/http/post.t
index 4caba8f..b3c0b7a 100644
--- a/t/http/post.t
+++ b/t/http/post.t
@@ -1,7 +1,7 @@
 use strict;
 use warnings;
 
-use Test::More tests => 3;
+use Test::More tests => 6;
 
 use_ok('Plient');
 use_ok('Plient::Test');
@@ -9,6 +9,10 @@ use_ok('Plient::Test');
 my $url = start_http_server();
 SKIP: {
     skip 'no plackup available', 1 unless $url;
-    is( plient( POST => "$url/hello", { body => { name => 'foo' } } ),
-        'hello foo', 'post /hello' );
+    # to test each handler, set env PLIENT_HANDLER_PREFERENCE_ONLY to true
+    for my $handler (qw/curl wget HTTPLite LWP/) {
+        Plient->handler_preference( http => [$handler] );
+        is( plient( POST => "$url/hello", { body => { name => 'foo' } } ),
+            'hello foo', 'post /hello' );
+    }
 }

commit 5508de8dc44e314698ce9b25789a0f43bb4f5da7
Author: sunnavy <sunnavy at bestpractical.com>
Date:   Tue Apr 20 21:09:17 2010 +0800

    http_post for HTTP::Lite

diff --git a/lib/Plient/Handler/HTTPLite.pm b/lib/Plient/Handler/HTTPLite.pm
index 958f781..9d2a8cd 100644
--- a/lib/Plient/Handler/HTTPLite.pm
+++ b/lib/Plient/Handler/HTTPLite.pm
@@ -31,6 +31,22 @@ sub init {
         }
     };
 
+    $method{http_post} = sub {
+        my ( $uri, $args ) = @_;
+        my $http  = HTTP::Lite->new;
+        $http->prepare_post( $args->{body} ) if $args->{body};
+        my $res = $http->request($uri) || '';
+        if ( $res == 200 || $res == 301 || $res == 302 ) {
+
+            # XXX TODO handle redirect
+            return $http->body;
+        }
+        else {
+            warn "failed to post $uri with HTTP::Lite: "  . $res;
+            return;
+        }
+    };
+
     return 1;
 }
 

commit 5a422bd8a0701e995c3cfa7caa4b562287de59a1
Author: sunnavy <sunnavy at bestpractical.com>
Date:   Tue Apr 20 21:36:40 2010 +0800

    move https stuff together code

diff --git a/lib/Plient/Handler/curl.pm b/lib/Plient/Handler/curl.pm
index 24ad0df..6e46ec0 100644
--- a/lib/Plient/Handler/curl.pm
+++ b/lib/Plient/Handler/curl.pm
@@ -40,7 +40,6 @@ sub init {
                 return;
             }
         };
-        $method{https_get} = $method{http_get} if exists $protocol{https};
 
         $method{http_post} = sub {
             my ( $uri, $args ) = @_;
@@ -77,6 +76,12 @@ sub init {
         };
     }
 
+    if ( exists $protocol{https} ) {
+        for my $m (qw/get post head put/) {
+            $method{"https_$m"} = $method{"http_$m"}
+              if exists $method{"http_$m"};
+        }
+    }
     return 1;
 }
 
diff --git a/lib/Plient/Handler/wget.pm b/lib/Plient/Handler/wget.pm
index eccb0e6..d5afe97 100644
--- a/lib/Plient/Handler/wget.pm
+++ b/lib/Plient/Handler/wget.pm
@@ -43,7 +43,6 @@ sub init {
             return;
         }
     };
-    $method{https_get} = $method{http_get} if exists $protocol{https};
 
     $method{http_post} = sub {
         my ( $uri, $args ) = @_;
@@ -78,6 +77,14 @@ sub init {
             return;
         }
     };
+
+    if ( exists $protocol{https} ) {
+        for my $m (qw/get post head put/) {
+            $method{"https_$m"} = $method{"http_$m"}
+              if exists $method{"http_$m"};
+        }
+    }
+
     return 1;
 }
 

commit 0ce8a56c46841f373cb9e09988a70aec64f504ce
Author: sunnavy <sunnavy at bestpractical.com>
Date:   Tue Apr 20 21:37:42 2010 +0800

    test message tweak

diff --git a/t/http/get.t b/t/http/get.t
index 5b3e6d5..91d4a66 100644
--- a/t/http/get.t
+++ b/t/http/get.t
@@ -12,6 +12,6 @@ SKIP: {
     # to test each handler, set env PLIENT_HANDLER_PREFERENCE_ONLY to true
     for my $handler (qw/curl wget HTTPLite LWP/) {
         Plient->handler_preference( http => [$handler] );
-        is( plient( GET => "$url/hello" ), 'hello', 'get /hello' );
+        is( plient( GET => "$url/hello" ), 'hello', "get /hello using $handler" );
     }
 }
diff --git a/t/http/post.t b/t/http/post.t
index b3c0b7a..ec076c3 100644
--- a/t/http/post.t
+++ b/t/http/post.t
@@ -13,6 +13,6 @@ SKIP: {
     for my $handler (qw/curl wget HTTPLite LWP/) {
         Plient->handler_preference( http => [$handler] );
         is( plient( POST => "$url/hello", { body => { name => 'foo' } } ),
-            'hello foo', 'post /hello' );
+            'hello foo', "post /hello using $handler" );
     }
 }

commit 0b47a64fc376cbe360f944753f8cbe6ec7e8210d
Author: sunnavy <sunnavy at bestpractical.com>
Date:   Tue Apr 20 21:37:53 2010 +0800

    basic http_post for lwp

diff --git a/lib/Plient/Handler/LWP.pm b/lib/Plient/Handler/LWP.pm
index c1da67d..cd7786f 100644
--- a/lib/Plient/Handler/LWP.pm
+++ b/lib/Plient/Handler/LWP.pm
@@ -38,6 +38,23 @@ sub init {
         }
     };
 
+    $method{http_post} = sub {
+        my ( $uri, $args ) = @_;
+
+        # XXX TODO tweak the new arguments
+        my $ua  = LWP::UserAgent->new;
+        my $res =
+          $ua->post( $uri,
+            $args->{body} ? ( content => $args->{body} ) : () );
+        if ( $res->is_success ) {
+            return $res->decoded_content;
+        }
+        else {
+            warn "failed to get $uri with lwp: " . $res->status_line;
+            return;
+        }
+    };
+
     if ( exists $protocol{https} ) {
         # have you seen https is available while http is not?
         $method{https_get} = $method{http_get};

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



More information about the Bps-public-commit mailing list