6 use Test::More tests => 98;
10 use File::Spec::Functions;
13 use File::Temp qw/ tempdir /;
15 my $path = catdir( getcwd(), 't', 'data', 'multipart' );
17 for ( my $i = 1; $i <= 12; $i++ ) {
19 my $test = sprintf( "%.3d", $i );
20 my $headers = YAML::LoadFile( catfile( $path, "$test-headers.yml" ) );
21 my $results = YAML::LoadFile( catfile( $path, "$test-results.yml" ) );
22 my $content = IO::File->new( catfile( $path, "$test-content.dat" ) );
23 my $body = HTTP::Body->new( $headers->{'Content-Type'}, $headers->{'Content-Length'} );
24 my $tempdir = tempdir( 'XXXXXXX', CLEANUP => 1, DIR => File::Spec->tmpdir() );
25 $body->tmpdir($tempdir);
27 my $regex_tempdir = quotemeta($tempdir);
29 binmode $content, ':raw';
31 while ( $content->read( my $buffer, 1024 ) ) {
35 # Save tempnames for later deletion
38 for my $field ( keys %{ $body->upload } ) {
40 my $value = $body->upload->{$field};
42 for ( ( ref($value) eq 'ARRAY' ) ? @{$value} : $value ) {
43 like($_->{tempname}, qr{$regex_tempdir}, "has tmpdir $tempdir");
44 push @temps, delete $_->{tempname};
48 is_deeply( $body->body, $results->{body}, "$test MultiPart body" );
49 is_deeply( $body->param, $results->{param}, "$test MultiPart param" );
50 is_deeply( $body->upload, $results->{upload}, "$test MultiPart upload" );
51 cmp_ok( $body->state, 'eq', 'done', "$test MultiPart state" );
52 cmp_ok( $body->length, '==', $body->content_length, "$test MultiPart length" );
54 # Clean up temp files created
55 unlink map { $_ } grep { -e $_ } @temps;