[Jifty-commit] r5992 - Net-Jifty/trunk/lib/Net

Jifty commits jifty-commit at lists.jifty.org
Mon Nov 17 09:35:32 EST 2008


Author: ruz
Date: Mon Nov 17 09:35:24 2008
New Revision: 5992

Modified:
   Net-Jifty/trunk/lib/Net/Jifty.pm

Log:
* add form_form_data_args method that transforms arguments into HTTP::Message
  objects ready to add into multipart/form-data request

Modified: Net-Jifty/trunk/lib/Net/Jifty.pm
==============================================================================
--- Net-Jifty/trunk/lib/Net/Jifty.pm	(original)
+++ Net-Jifty/trunk/lib/Net/Jifty.pm	Mon Nov 17 09:35:24 2008
@@ -213,6 +213,35 @@
     return $uri;
 }
 
+sub form_form_data_args {
+    my $self = shift;
+
+    my @res;
+    while (my ($key, $value) = splice @_, 0, 2) {
+        my $disposition = 'form-data; name="'. Encode::encode( 'MIME-Q', $key ) .'"';
+        unless ( ref $value ) {
+            push @res, HTTP::Message->new(
+                ['Content-Disposition' => $disposition ],
+                $value,
+            );
+            next;
+        }
+        
+        if ( $value->{'filename'} ) {
+            $value->{'filename'} = Encode::encode( 'MIME-Q', $value->{'filename'} );
+            $disposition .= '; filename="'. delete ( $value->{'filename'} ) .'"';
+        }
+        push @res, HTTP::Message->new(
+            [
+                'Content-Type' => $value->{'content_type'} || 'application/octet-stream',
+                'Content-Disposition' => $disposition,
+            ],
+            delete $value->{content},
+        );
+    }
+    return @res;
+}
+
 sub method {
     my $self   = shift;
     my $method = lc(shift);


More information about the Jifty-commit mailing list