From: Torsten Raudssus Date: Tue, 26 Oct 2010 17:13:40 +0000 (+0000) Subject: Add version 1.11 of HTTP::Body with new param_order functionality X-Git-Tag: v1.11^0 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=08160cca69ee960a312c88410dd5c5b3b376a577;hp=e0c37f8e56e19ce6a767ced61f8300891da095ff;p=catagits%2FHTTP-Body.git Add version 1.11 of HTTP::Body with new param_order functionality Also documented, also added to the tests. --- diff --git a/Changes b/Changes index 2c0ac4a..0374d61 100644 --- a/Changes +++ b/Changes @@ -1,5 +1,8 @@ This file documents the revision history for Perl extension HTTP::Body. +1.11 Tue 26 Oct 2010 14:10:00 UTC + - Added param_order capability (Torsten Raudssus [GETTY]) + 1.10 Fri 8 Oct 2010 15:50:55 UTC - Patch for test failure ( thanks KENTNL/MITHALDU! ) diff --git a/dist.ini b/dist.ini index 3ef0abd..aa19c18 100644 --- a/dist.ini +++ b/dist.ini @@ -1,5 +1,5 @@ name = HTTP-Body -version = 1.10 +version = 1.11 author = Christian Hansen, C author = Sebastian Riedel, C author = Andy Grundman, C diff --git a/lib/HTTP/Body.pm b/lib/HTTP/Body.pm index 9b41753..acecd21 100644 --- a/lib/HTTP/Body.pm +++ b/lib/HTTP/Body.pm @@ -47,9 +47,10 @@ HTTP::Body - HTTP Body Parser $body->add($buffer); } - my $uploads = $body->upload; # hashref - my $params = $body->param; # hashref - my $body = $body->body; # IO::Handle + my $uploads = $body->upload; # hashref + my $params = $body->param; # hashref + my $param_order = $body->param_order # arrayref + my $body = $body->body; # IO::Handle } =head1 DESCRIPTION @@ -106,6 +107,7 @@ sub new { content_type => $content_type, length => 0, param => {}, + param_order => [], state => 'buffering', upload => {}, tmpdir => File::Spec->tmpdir(), @@ -344,6 +346,8 @@ sub param { else { $self->{param}->{$name} = $value; } + + push @{$self->{param_order}}, $name; } return $self->{param}; @@ -388,6 +392,16 @@ sub tmpdir { return $self->{tmpdir}; } +=item param_order + +Returns the array ref of the param keys in the order how they appeared on the body + +=cut + +sub param_order { + return shift->{param_order}; +} + =back =head1 SUPPORT @@ -420,6 +434,8 @@ Kent Fredric Christian Walde +Torsten Raudssus + =head1 LICENSE This library is free software. You can redistribute it and/or modify diff --git a/t/04multipart.t b/t/04multipart.t index b64b8bb..074ca10 100644 --- a/t/04multipart.t +++ b/t/04multipart.t @@ -6,7 +6,7 @@ use warnings; use FindBin; use lib "$FindBin::Bin/lib"; -use Test::More tests => 140; +use Test::More tests => 153; use Test::Deep; use Cwd; @@ -63,9 +63,10 @@ for ( my $i = 1; $i <= 13; $i++ ) { $results->{upload}->{$field}->{tempname} = ignore(); } } - + cmp_deeply( $body->body, $results->{body}, "$test MultiPart body" ); cmp_deeply( $body->param, $results->{param}, "$test MultiPart param" ); + cmp_deeply( $body->param_order, $results->{param_order} ? $results->{param_order} : [], "$test MultiPart param_order" ); cmp_deeply( $body->upload, $results->{upload}, "$test MultiPart upload" ) if $results->{upload}; cmp_ok( $body->state, 'eq', 'done', "$test MultiPart state" ); @@ -82,4 +83,5 @@ for ( my $i = 1; $i <= 13; $i++ ) { for my $temp ( @temps ) { ok( !-e $temp, "Temp file $temp was deleted" ); } + } diff --git a/t/05urlencoded.t b/t/05urlencoded.t index f92a9b6..8654b00 100644 --- a/t/05urlencoded.t +++ b/t/05urlencoded.t @@ -6,7 +6,7 @@ use warnings; use FindBin; use lib "$FindBin::Bin/lib"; -use Test::More tests => 31; +use Test::More tests => 37; use Cwd; use Digest::MD5 qw(md5_hex); @@ -33,6 +33,7 @@ for ( my $i = 1; $i <= 6; $i++ ) { is_deeply( $body->body, $results->{body}, "$test UrlEncoded body" ); is_deeply( $body->param, $results->{param}, "$test UrlEncoded param" ); + is_deeply( $body->param_order, $results->{param_order} ? $results->{param_order} : [], "$test UrlEncoded param_order" ); is_deeply( $body->upload, $results->{upload}, "$test UrlEncoded upload" ); cmp_ok( $body->state, 'eq', 'done', "$test UrlEncoded state" ); cmp_ok( $body->length, '==', $body->content_length, "$test UrlEncoded length" ); diff --git a/t/07xforms.t b/t/07xforms.t index 382cead..fdf6587 100644 --- a/t/07xforms.t +++ b/t/07xforms.t @@ -6,7 +6,7 @@ use warnings; use FindBin; use lib "$FindBin::Bin/lib"; -use Test::More tests => 12; +use Test::More tests => 14; use Cwd; use HTTP::Body; @@ -44,6 +44,7 @@ for ( my $i = 1; $i <= 2; $i++ ) { is_deeply( $body->body, $results->{body}, "$test XForms body" ); is_deeply( $body->param, $results->{param}, "$test XForms param" ); + is_deeply( $body->param_order, $results->{param_order} ? $results->{param_order} : [], "$test XForms param_order" ); is_deeply( $body->upload, $results->{upload}, "$test XForms upload" ); if ( $body->isa('HTTP::Body::XFormsMultipart') ) { cmp_ok( $body->start, 'eq', $results->{start}, "$test XForms start" ); diff --git a/t/data/multipart/001-results.pml b/t/data/multipart/001-results.pml index dd4085a..c866422 100644 --- a/t/data/multipart/001-results.pml +++ b/t/data/multipart/001-results.pml @@ -56,5 +56,8 @@ "A", "B" ] - } + }, + "param_order" => [ + "text1", "text2", "select", "select", "textarea" + ] } diff --git a/t/data/multipart/002-results.pml b/t/data/multipart/002-results.pml index b73fec4..979b3a0 100644 --- a/t/data/multipart/002-results.pml +++ b/t/data/multipart/002-results.pml @@ -39,5 +39,8 @@ "A", "B" ] - } + }, + "param_order" => [ + "text1", "text2", "select", "select", "textarea" + ] } diff --git a/t/data/multipart/003-results.pml b/t/data/multipart/003-results.pml index ae3597c..f166735 100644 --- a/t/data/multipart/003-results.pml +++ b/t/data/multipart/003-results.pml @@ -36,5 +36,8 @@ "A", "B" ] - } + }, + "param_order" => [ + "text1", "text2", "select", "select", "textarea" + ] } diff --git a/t/data/multipart/004-results.pml b/t/data/multipart/004-results.pml index 9a5d69f..dfc2984 100644 --- a/t/data/multipart/004-results.pml +++ b/t/data/multipart/004-results.pml @@ -39,5 +39,8 @@ "A", "B" ] - } + }, + "param_order" => [ + "text1", "text2", "select", "select", "textarea" + ] } diff --git a/t/data/multipart/005-results.pml b/t/data/multipart/005-results.pml index 95f31e2..898702a 100644 --- a/t/data/multipart/005-results.pml +++ b/t/data/multipart/005-results.pml @@ -39,5 +39,8 @@ "A", "B" ] - } + }, + "param_order" => [ + "text1", "text2", "select", "select", "textarea" + ] } diff --git a/t/data/multipart/006-results.pml b/t/data/multipart/006-results.pml index b5ee5e6..53d4a4c 100644 --- a/t/data/multipart/006-results.pml +++ b/t/data/multipart/006-results.pml @@ -39,5 +39,8 @@ "A", "B" ] - } + }, + "param_order" => [ + "text1", "text2", "select", "select", "textarea" + ] } diff --git a/t/data/multipart/007-results.pml b/t/data/multipart/007-results.pml index 9a5d69f..dfc2984 100644 --- a/t/data/multipart/007-results.pml +++ b/t/data/multipart/007-results.pml @@ -39,5 +39,8 @@ "A", "B" ] - } + }, + "param_order" => [ + "text1", "text2", "select", "select", "textarea" + ] } diff --git a/t/data/multipart/008-results.pml b/t/data/multipart/008-results.pml index b5ee5e6..53d4a4c 100644 --- a/t/data/multipart/008-results.pml +++ b/t/data/multipart/008-results.pml @@ -39,5 +39,8 @@ "A", "B" ] - } + }, + "param_order" => [ + "text1", "text2", "select", "select", "textarea" + ] } diff --git a/t/data/multipart/009-results.pml b/t/data/multipart/009-results.pml index 2907b2f..aab39d0 100644 --- a/t/data/multipart/009-results.pml +++ b/t/data/multipart/009-results.pml @@ -39,5 +39,8 @@ "A", "B" ] - } + }, + "param_order" => [ + "text1", "text2", "select", "select", "textarea" + ] } diff --git a/t/data/multipart/010-results.pml b/t/data/multipart/010-results.pml index 5d11a0a..88f3b13 100644 --- a/t/data/multipart/010-results.pml +++ b/t/data/multipart/010-results.pml @@ -37,5 +37,8 @@ "A", "B" ] - } + }, + "param_order" => [ + "text1", "text2", "select", "select", "textarea" + ] } diff --git a/t/data/multipart/011-results.pml b/t/data/multipart/011-results.pml index 5d11a0a..88f3b13 100644 --- a/t/data/multipart/011-results.pml +++ b/t/data/multipart/011-results.pml @@ -37,5 +37,8 @@ "A", "B" ] - } + }, + "param_order" => [ + "text1", "text2", "select", "select", "textarea" + ] } diff --git a/t/data/multipart/012-results.pml b/t/data/multipart/012-results.pml index 5d11a0a..88f3b13 100644 --- a/t/data/multipart/012-results.pml +++ b/t/data/multipart/012-results.pml @@ -37,5 +37,8 @@ "A", "B" ] - } + }, + "param_order" => [ + "text1", "text2", "select", "select", "textarea" + ] } diff --git a/t/data/multipart/013-results.pml b/t/data/multipart/013-results.pml index aa9d747..0948a94 100644 --- a/t/data/multipart/013-results.pml +++ b/t/data/multipart/013-results.pml @@ -8,5 +8,8 @@ "A", "B" ] - } + }, + "param_order" => [ + "text1", "text2", "select", "select", "textarea" + ] } diff --git a/t/data/urlencoded/001-results.pml b/t/data/urlencoded/001-results.pml index 574091d..0fd5ba2 100644 --- a/t/data/urlencoded/001-results.pml +++ b/t/data/urlencoded/001-results.pml @@ -10,5 +10,8 @@ "A", "B" ] - } + }, + "param_order" => [ + "text1", "text2", "select", "select", "textarea", "encoding" + ] } diff --git a/t/data/urlencoded/002-results.pml b/t/data/urlencoded/002-results.pml index 1fd9cff..5461aa5 100644 --- a/t/data/urlencoded/002-results.pml +++ b/t/data/urlencoded/002-results.pml @@ -4,5 +4,8 @@ "param" => { "one" => "foo", "two" => "bar" - } + }, + "param_order" => [ + "one", "two" + ], } diff --git a/t/data/urlencoded/003-results.pml b/t/data/urlencoded/003-results.pml index 574091d..0fd5ba2 100644 --- a/t/data/urlencoded/003-results.pml +++ b/t/data/urlencoded/003-results.pml @@ -10,5 +10,8 @@ "A", "B" ] - } + }, + "param_order" => [ + "text1", "text2", "select", "select", "textarea", "encoding" + ] } diff --git a/t/data/urlencoded/004-results.pml b/t/data/urlencoded/004-results.pml index 1fd9cff..1cd75c1 100644 --- a/t/data/urlencoded/004-results.pml +++ b/t/data/urlencoded/004-results.pml @@ -4,5 +4,8 @@ "param" => { "one" => "foo", "two" => "bar" - } + }, + "param_order" => [ + "one", "two" + ] } diff --git a/t/data/urlencoded/005-results.pml b/t/data/urlencoded/005-results.pml index 1fd9cff..1cd75c1 100644 --- a/t/data/urlencoded/005-results.pml +++ b/t/data/urlencoded/005-results.pml @@ -4,5 +4,8 @@ "param" => { "one" => "foo", "two" => "bar" - } + }, + "param_order" => [ + "one", "two" + ] } diff --git a/t/data/urlencoded/006-results.pml b/t/data/urlencoded/006-results.pml index c44c760..1a13c7e 100644 --- a/t/data/urlencoded/006-results.pml +++ b/t/data/urlencoded/006-results.pml @@ -4,5 +4,8 @@ "param" => { "one" => "foo", "two" => "bar=bam" - } + }, + "param_order" => [ + "one", "two" + ] } diff --git a/t/data/xforms/001-results.pml b/t/data/xforms/001-results.pml index 6b87330..577f7a5 100644 --- a/t/data/xforms/001-results.pml +++ b/t/data/xforms/001-results.pml @@ -21,5 +21,8 @@ "param" => { "XForms:Model" => "asdfgasdfg" }, + param_order => [ + "XForms:Model" + ], "start" => "asdfg\@asdfg.com" } diff --git a/t/data/xforms/002-results.pml b/t/data/xforms/002-results.pml index a55b4b6..f0a53df 100644 --- a/t/data/xforms/002-results.pml +++ b/t/data/xforms/002-results.pml @@ -3,5 +3,8 @@ "upload" => {}, "param" => { "XForms:Model" => "asdfgasdfg" - } + }, + param_order => [ + "XForms:Model" + ] }