@@ -5,6 +5,7 @@ use HTTP::Entity::Parser::MultiPart;
55use Hash::MultiValue;
66use HTTP::Headers;
77use t::Util;
8+ use File::Basename;
89
910my $content = qq{ ------BOUNDARY
1011Content-Disposition: form-data; name="hoge"
@@ -59,41 +60,49 @@ SHOGUN6
5960$content =~ s /\r\n / \n / g ;
6061$content =~ s /\n / \r\n / g ;
6162
62- my $env = {
63- CONTENT_LENGTH => length ($content ),
64- CONTENT_TYPE => ' multipart/form-data; boundary=----BOUNDARY' ,
65- };
66-
67- # read from file.
68- my $parser = HTTP::Entity::Parser::MultiPart-> new($env );
69- $parser -> add($_ ) for split //, $content ;
70- my ($params , $uploads ) = $parser -> finalize();
71-
72- is_deeply( Hash::MultiValue-> new(@$params )-> as_hashref_multi, {
73- hoge => [' fuga' , ' hige' ],
74- nobuko => [' iwaki' ],
75- });
76-
77- $uploads = Hash::MultiValue-> new(@$uploads );
78-
79- my @test_upload_file = $uploads -> get_all(' test_upload_file' );
80- is 0+@test_upload_file , 2;
81- is slurp($test_upload_file [0]-> {tempname }), ' SHOGUN' ;
82- is slurp($test_upload_file [1]-> {tempname }), ' SHOGUN2' ;
63+ my $tmpdir ;
8364
8465{
85- my $test_upload_file3 = $uploads -> {' test_upload_file3' };
86- is slurp($test_upload_file3 -> {tempname }), ' SHOGUN3' ;
87-
88- my @test_upload_file6 = $uploads -> {' test_upload_file6' };
89- is slurp($test_upload_file6 [0]-> {tempname }), ' SHOGUN6' ;
90- my $header = HTTP::Headers-> new(@{$test_upload_file6 [0]-> {headers }});
91- is $header -> header(' Content-Type' ), ' text/plain' ;
92- is $header -> content_type, ' text/plain' ;
93- is $header -> header(' X' ), ' Y:Z' ;
94- is $header -> header(' Foo' ), ' bar baz' ;
66+ my $env = {
67+ CONTENT_LENGTH => length ($content ),
68+ CONTENT_TYPE => ' multipart/form-data; boundary=----BOUNDARY' ,
69+ };
70+
71+ # read from file.
72+ my $parser = HTTP::Entity::Parser::MultiPart-> new($env );
73+ $parser -> add($_ ) for split //, $content ;
74+ my ($params , $uploads ) = $parser -> finalize();
75+
76+ is_deeply( Hash::MultiValue-> new(@$params )-> as_hashref_multi, {
77+ hoge => [' fuga' , ' hige' ],
78+ nobuko => [' iwaki' ],
79+ });
80+
81+ $uploads = Hash::MultiValue-> new(@$uploads );
82+
83+ my @test_upload_file = $uploads -> get_all(' test_upload_file' );
84+ is 0+@test_upload_file , 2;
85+ is slurp($test_upload_file [0]-> {tempname }), ' SHOGUN' ;
86+ is slurp($test_upload_file [1]-> {tempname }), ' SHOGUN2' ;
87+
88+ {
89+ my $test_upload_file3 = $uploads -> {' test_upload_file3' };
90+ is slurp($test_upload_file3 -> {tempname }), ' SHOGUN3' ;
91+
92+ my @test_upload_file6 = $uploads -> {' test_upload_file6' };
93+ is slurp($test_upload_file6 [0]-> {tempname }), ' SHOGUN6' ;
94+ my $header = HTTP::Headers-> new(@{$test_upload_file6 [0]-> {headers }});
95+ is $header -> header(' Content-Type' ), ' text/plain' ;
96+ is $header -> content_type, ' text/plain' ;
97+ is $header -> header(' X' ), ' Y:Z' ;
98+ is $header -> header(' Foo' ), ' bar baz' ;
99+ }
100+
101+ $tmpdir = dirname($test_upload_file [0]-> {tempname });
95102}
96103
104+ ok(! -d $tmpdir );
105+
97106done_testing();
98107
99108
0 commit comments