[Bps-public-commit] plient branch, master, updated. b0411e71a214f018b36b565ef2ae6de323579606
? sunnavy
sunnavy at bestpractical.com
Tue May 4 04:58:57 EDT 2010
The branch, master has been updated
via b0411e71a214f018b36b565ef2ae6de323579606 (commit)
via b1bd3616414c83b25a5f885042551b597281d430 (commit)
from 7c12af7741eb7846415a542f5d1754d855ba5464 (commit)
Summary of changes:
lib/Plient.pm | 15 ++++++++++++++-
lib/Plient/Handler/LWP.pm | 12 ++++++++++--
lib/Plient/Handler/curl.pm | 13 +++++++++++--
3 files changed, 35 insertions(+), 5 deletions(-)
- Log -----------------------------------------------------------------
commit b1bd3616414c83b25a5f885042551b597281d430
Author: sunnavy <sunnavy at bestpractical.com>
Date: Tue May 4 16:58:42 2010 +0800
multiple values for file uploads too
diff --git a/lib/Plient/Handler/LWP.pm b/lib/Plient/Handler/LWP.pm
index 98f959e..ae3b237 100644
--- a/lib/Plient/Handler/LWP.pm
+++ b/lib/Plient/Handler/LWP.pm
@@ -59,8 +59,16 @@ sub init {
for my $k ( keys %{ $args->{body} } ) {
if ( my $ref = ref $args->{body}{$k} ) {
if ( $ref eq 'ARRAY' ) {
- push @$content, $k, $args->{body}{$k}{$_}
- for @{ $args->{body}{$k} };
+ for my $i ( @{ $args->{body}{$k} } ) {
+ if ( ref $i eq 'HASH' && $i->{file} ) {
+
+ # file upload
+ push @$content, $k, [ $i->{file} ];
+ }
+ else {
+ push @$content, $k, $i;
+ }
+ }
}
elsif ( $ref eq 'HASH' ) {
diff --git a/lib/Plient/Handler/curl.pm b/lib/Plient/Handler/curl.pm
index 0b550f3..5d78540 100644
--- a/lib/Plient/Handler/curl.pm
+++ b/lib/Plient/Handler/curl.pm
@@ -70,11 +70,20 @@ sub init {
if ( ref $kv{$k} ) {
if ( ref $kv{$k} eq 'ARRAY' ) {
for my $i ( @{ $kv{$k} } ) {
- $data .= " $post_opt '$k=$i'";
+ if ( ref $i eq 'HASH'
+ && $i->{file} )
+ {
+ # file upload
+ $data .= " $post_opt '$k=\@$i->{file}'";
+ }
+ else {
+ $data .= " $post_opt '$k=$i'";
+ }
}
}
elsif ( ref $kv{$k} eq 'HASH' && $kv{$k}{file} ) {
- $data .= " $post_opt '\@$kv{$k}{file}'";
+ # file upload
+ $data .= " $post_opt '$k=\@$kv{$k}{file}'";
}
else {
warn "invalid body value of $k: $kv{$k}";
commit b0411e71a214f018b36b565ef2ae6de323579606
Author: sunnavy <sunnavy at bestpractical.com>
Date: Tue May 4 16:59:07 2010 +0800
pod update, for file upload
diff --git a/lib/Plient.pm b/lib/Plient.pm
index 6de62e5..91aa663 100644
--- a/lib/Plient.pm
+++ b/lib/Plient.pm
@@ -298,6 +298,12 @@ for HTTP(S), these will be used to set Authorization header
=item auth_method
currently, only 'Basic' is supported, default is 'Basic'
+
+=item content_type
+
+for HTTP(S), specify the Contnet-Type of post data.
+ availables are 'urlencoded' and 'form-data'.
+ default is 'urlencoded'.
=item headers
@@ -307,7 +313,14 @@ hashref, this will be sent as HTTP(S) headers. e.g.
=item body
hashref, this will be sent as HTTP(S) post data. e.g.
- { 'title' => 'foo', body => 'bar' }
+ {
+ title => 'foo',
+ body => 'bar',
+ foo => [ 'bar', 'baz' ],
+ file1 => { file => '/path/to/file' },
+ }
+
+ if one value is hashref with file key, it's interpreted as a file upload
=back
-----------------------------------------------------------------------
More information about the Bps-public-commit
mailing list