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

? sunnavy sunnavy at bestpractical.com
Mon Apr 19 19:29:38 EDT 2010


The branch, master has been updated
       via  e5b146c5a063693e62a2a88a77cfc855ad40faa5 (commit)
      from  c9c338717ea5edfa34186fafc4516476510bad02 (commit)

Summary of changes:
 lib/Plient/Handler/wget.pm |   38 ++++++++++++++++++++++++++++++++++++--
 1 files changed, 36 insertions(+), 2 deletions(-)

- Log -----------------------------------------------------------------
commit e5b146c5a063693e62a2a88a77cfc855ad40faa5
Author: sunnavy <sunnavy at bestpractical.com>
Date:   Tue Apr 20 07:29:44 2010 +0800

    basic post for wget

diff --git a/lib/Plient/Handler/wget.pm b/lib/Plient/Handler/wget.pm
index 785acbe..eccb0e6 100644
--- a/lib/Plient/Handler/wget.pm
+++ b/lib/Plient/Handler/wget.pm
@@ -22,7 +22,7 @@ sub init {
     $wget = $ENV{PLIENT_WGET} || which('wget');
     return unless $wget;
 
-    @protocol{qw/http https ftp/}     = ();
+    @protocol{qw/http https ftp/} = ();
 
     {
         local $ENV{LC_ALL} = 'en_US';
@@ -31,7 +31,7 @@ sub init {
             delete $protocol{https};
         }
     }
-    
+
     $method{http_get} = sub {
         my ( $uri, $args ) = @_;
         if ( open my $fh, "$wget -q -O - $uri |" ) {
@@ -44,6 +44,40 @@ sub init {
         }
     };
     $method{https_get} = $method{http_get} if exists $protocol{https};
+
+    $method{http_post} = sub {
+        my ( $uri, $args ) = @_;
+        $args ||= {};
+
+        my $data = '';
+        if ( $args->{body} ) {
+            my %kv = %{ $args->{body} };
+            for my $k ( keys %kv ) {
+                if ( defined $kv{$k} ) {
+                    if ( ref $kv{$k} && ref $kv{$k} eq 'ARRAY' ) {
+                        for my $i ( @{ $kv{$k} } ) {
+                            $data .= " --post-data $k=$i";
+                        }
+                    }
+                    else {
+                        $data .= " --post-data $k=$kv{$k}";
+                    }
+                }
+                else {
+                    $data .= " --post-data $k=";
+                }
+            }
+        }
+
+        if ( open my $fh, "$wget -q -O - $data $uri |" ) {
+            local $/;
+            <$fh>;
+        }
+        else {
+            warn "failed to post $uri with curl: $!";
+            return;
+        }
+    };
     return 1;
 }
 

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



More information about the Bps-public-commit mailing list