[Catalyst-commits] r7939 - in trunk/HTTP-Body: . lib/HTTP lib/HTTP/Body t

andyg at dev.catalyst.perl.org andyg at dev.catalyst.perl.org
Mon Jun 23 20:41:32 BST 2008


Author: andyg
Date: 2008-06-23 20:41:32 +0100 (Mon, 23 Jun 2008)
New Revision: 7939

Modified:
   trunk/HTTP-Body/Changes
   trunk/HTTP-Body/README
   trunk/HTTP-Body/lib/HTTP/Body.pm
   trunk/HTTP-Body/lib/HTTP/Body/MultiPart.pm
   trunk/HTTP-Body/lib/HTTP/Body/OctetStream.pm
   trunk/HTTP-Body/t/04multipart.t
Log:
HTTP::Body 1.04, patch from jgoulah for tmpdir() accessor

Modified: trunk/HTTP-Body/Changes
===================================================================
--- trunk/HTTP-Body/Changes	2008-06-23 13:38:24 UTC (rev 7938)
+++ trunk/HTTP-Body/Changes	2008-06-23 19:41:32 UTC (rev 7939)
@@ -1,5 +1,9 @@
 This file documents the revision history for Perl extension HTTP::Body.
 
+1.04    2008-06-23 16:00:00
+        - Added tmpdir() accessor to specify an alternate directory for temp files.
+          (jgoulah)
+
 1.03    2008-04-07 08:20:00
         - Set body value for XForms data. (Daniel Ruoso)
 

Modified: trunk/HTTP-Body/README
===================================================================
--- trunk/HTTP-Body/README	2008-06-23 13:38:24 UTC (rev 7938)
+++ trunk/HTTP-Body/README	2008-06-23 19:41:32 UTC (rev 7939)
@@ -84,6 +84,10 @@
     upload
         Get/set file uploads.
 
+    tmpdir
+        Specify a different path for temporary files. Defaults to the system
+        temporary path.
+
 AUTHOR
     Christian Hansen, "ch at ngmedia.com"
 

Modified: trunk/HTTP-Body/lib/HTTP/Body/MultiPart.pm
===================================================================
--- trunk/HTTP-Body/lib/HTTP/Body/MultiPart.pm	2008-06-23 13:38:24 UTC (rev 7938)
+++ trunk/HTTP-Body/lib/HTTP/Body/MultiPart.pm	2008-06-23 19:41:32 UTC (rev 7939)
@@ -270,7 +270,7 @@
             $part->{filename} = $filename;
 
             if ( $filename ne "" ) {
-                my $fh = File::Temp->new( UNLINK => 0 );
+                my $fh = File::Temp->new( UNLINK => 0, DIR => $self->tmpdir );
 
                 $part->{fh}       = $fh;
                 $part->{tempname} = $fh->filename;

Modified: trunk/HTTP-Body/lib/HTTP/Body/OctetStream.pm
===================================================================
--- trunk/HTTP-Body/lib/HTTP/Body/OctetStream.pm	2008-06-23 13:38:24 UTC (rev 7938)
+++ trunk/HTTP-Body/lib/HTTP/Body/OctetStream.pm	2008-06-23 19:41:32 UTC (rev 7939)
@@ -30,7 +30,7 @@
     my $self = shift;
 
     unless ( $self->body ) {
-        $self->body( File::Temp->new );
+        $self->body( File::Temp->new( DIR => $self->tmpdir ) );
     }
 
     if ( my $length = length( $self->{buffer} ) ) {

Modified: trunk/HTTP-Body/lib/HTTP/Body.pm
===================================================================
--- trunk/HTTP-Body/lib/HTTP/Body.pm	2008-06-23 13:38:24 UTC (rev 7938)
+++ trunk/HTTP-Body/lib/HTTP/Body.pm	2008-06-23 19:41:32 UTC (rev 7939)
@@ -4,7 +4,7 @@
 
 use Carp       qw[ ];
 
-our $VERSION = '1.03';
+our $VERSION = '1.04';
 
 our $TYPES = {
     'application/octet-stream'          => 'HTTP::Body::OctetStream',
@@ -113,7 +113,8 @@
         length         => 0,
         param          => {},
         state          => 'buffering',
-        upload         => {}
+        upload         => {},
+        tmpdir         => File::Spec->tmpdir(),
     };
 
     bless( $self, $body );
@@ -355,6 +356,18 @@
     return $self->{upload};
 }
 
+=item tmpdir 
+
+Specify a different path for temporary files.  Defaults to the system temporary path.
+
+=cut
+
+sub tmpdir {
+    my $self = shift;
+    $self->{tmpdir} = shift if @_;
+    return $self->{tmpdir};
+}
+
 =back
 
 =head1 AUTHOR

Modified: trunk/HTTP-Body/t/04multipart.t
===================================================================
--- trunk/HTTP-Body/t/04multipart.t	2008-06-23 13:38:24 UTC (rev 7938)
+++ trunk/HTTP-Body/t/04multipart.t	2008-06-23 19:41:32 UTC (rev 7939)
@@ -3,13 +3,14 @@
 use strict;
 use warnings;
 
-use Test::More tests => 60;
+use Test::More tests => 98;
 
 use Cwd;
 use HTTP::Body;
 use File::Spec::Functions;
 use IO::File;
 use YAML;
+use File::Temp qw/ tempdir /;
 
 my $path = catdir( getcwd(), 't', 'data', 'multipart' );
 
@@ -20,7 +21,11 @@
     my $results = YAML::LoadFile( catfile( $path, "$test-results.yml" ) );
     my $content = IO::File->new( catfile( $path, "$test-content.dat" ) );
     my $body    = HTTP::Body->new( $headers->{'Content-Type'}, $headers->{'Content-Length'} );
+    my $tempdir = tempdir( 'XXXXXXX', CLEANUP => 1, DIR => File::Spec->tmpdir() );
+    $body->tmpdir($tempdir);
 
+    my $regex_tempdir = quotemeta($tempdir);
+
     binmode $content, ':raw';
 
     while ( $content->read( my $buffer, 1024 ) ) {
@@ -35,6 +40,7 @@
         my $value = $body->upload->{$field};
 
         for ( ( ref($value) eq 'ARRAY' ) ? @{$value} : $value ) {
+            like($_->{tempname}, qr{$regex_tempdir}, "has tmpdir $tempdir");
             push @temps, delete $_->{tempname};
         }
     }




More information about the Catalyst-commits mailing list