Add version 1.11 of HTTP::Body with new param_order functionality v1.11
Torsten Raudssus [Tue, 26 Oct 2010 17:13:40 +0000 (17:13 +0000)]
Also documented, also added to the tests.

27 files changed:
Changes
dist.ini
lib/HTTP/Body.pm
t/04multipart.t
t/05urlencoded.t
t/07xforms.t
t/data/multipart/001-results.pml
t/data/multipart/002-results.pml
t/data/multipart/003-results.pml
t/data/multipart/004-results.pml
t/data/multipart/005-results.pml
t/data/multipart/006-results.pml
t/data/multipart/007-results.pml
t/data/multipart/008-results.pml
t/data/multipart/009-results.pml
t/data/multipart/010-results.pml
t/data/multipart/011-results.pml
t/data/multipart/012-results.pml
t/data/multipart/013-results.pml
t/data/urlencoded/001-results.pml
t/data/urlencoded/002-results.pml
t/data/urlencoded/003-results.pml
t/data/urlencoded/004-results.pml
t/data/urlencoded/005-results.pml
t/data/urlencoded/006-results.pml
t/data/xforms/001-results.pml
t/data/xforms/002-results.pml

diff --git a/Changes b/Changes
index 2c0ac4a..0374d61 100644 (file)
--- 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! )
 
index 3ef0abd..aa19c18 100644 (file)
--- a/dist.ini
+++ b/dist.ini
@@ -1,5 +1,5 @@
 name    = HTTP-Body
-version = 1.10
+version = 1.11
 author  = Christian Hansen, C<chansen@cpan.org>
 author  = Sebastian Riedel, C<sri@cpan.org>
 author  = Andy Grundman, C<andy@hybridized.org>
index 9b41753..acecd21 100644 (file)
@@ -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 <kentnl@cpan.org>
 
 Christian Walde
 
+Torsten Raudssus <torsten@raudssus.de>
+
 =head1 LICENSE
 
 This library is free software. You can redistribute it and/or modify 
index b64b8bb..074ca10 100644 (file)
@@ -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" );
     }
+
 } 
index f92a9b6..8654b00 100644 (file)
@@ -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" );
index 382cead..fdf6587 100644 (file)
@@ -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" );
index dd4085a..c866422 100644 (file)
@@ -56,5 +56,8 @@
       "A",
       "B"
     ]
-  }
+  },
+  "param_order" => [
+    "text1", "text2", "select", "select", "textarea"
+  ]
 }
index b73fec4..979b3a0 100644 (file)
@@ -39,5 +39,8 @@
       "A",
       "B"
     ]
-  }
+  },
+  "param_order" => [
+    "text1", "text2", "select", "select", "textarea"
+  ]
 }
index ae3597c..f166735 100644 (file)
@@ -36,5 +36,8 @@
       "A",
       "B"
     ]
-  }
+  },
+  "param_order" => [
+    "text1", "text2", "select", "select", "textarea"
+  ]
 }
index 9a5d69f..dfc2984 100644 (file)
@@ -39,5 +39,8 @@
       "A",
       "B"
     ]
-  }
+  },
+  "param_order" => [
+    "text1", "text2", "select", "select", "textarea"
+  ]
 }
index 95f31e2..898702a 100644 (file)
@@ -39,5 +39,8 @@
       "A",
       "B"
     ]
-  }
+  },
+  "param_order" => [
+    "text1", "text2", "select", "select", "textarea"
+  ]
 }
index b5ee5e6..53d4a4c 100644 (file)
@@ -39,5 +39,8 @@
       "A",
       "B"
     ]
-  }
+  },
+  "param_order" => [
+    "text1", "text2", "select", "select", "textarea"
+  ]
 }
index 9a5d69f..dfc2984 100644 (file)
@@ -39,5 +39,8 @@
       "A",
       "B"
     ]
-  }
+  },
+  "param_order" => [
+    "text1", "text2", "select", "select", "textarea"
+  ]
 }
index b5ee5e6..53d4a4c 100644 (file)
@@ -39,5 +39,8 @@
       "A",
       "B"
     ]
-  }
+  },
+  "param_order" => [
+    "text1", "text2", "select", "select", "textarea"
+  ]
 }
index 2907b2f..aab39d0 100644 (file)
@@ -39,5 +39,8 @@
       "A",
       "B"
     ]
-  }
+  },
+  "param_order" => [
+    "text1", "text2", "select", "select", "textarea"
+  ]
 }
index 5d11a0a..88f3b13 100644 (file)
@@ -37,5 +37,8 @@
       "A",
       "B"
     ]
-  }
+  },
+  "param_order" => [
+    "text1", "text2", "select", "select", "textarea"
+  ]
 }
index 5d11a0a..88f3b13 100644 (file)
@@ -37,5 +37,8 @@
       "A",
       "B"
     ]
-  }
+  },
+  "param_order" => [
+    "text1", "text2", "select", "select", "textarea"
+  ]
 }
index 5d11a0a..88f3b13 100644 (file)
@@ -37,5 +37,8 @@
       "A",
       "B"
     ]
-  }
+  },
+  "param_order" => [
+    "text1", "text2", "select", "select", "textarea"
+  ]
 }
index aa9d747..0948a94 100644 (file)
@@ -8,5 +8,8 @@
       "A",
       "B"
     ]
-  }
+  },
+  "param_order" => [
+    "text1", "text2", "select", "select", "textarea"
+  ]
 }
index 574091d..0fd5ba2 100644 (file)
@@ -10,5 +10,8 @@
       "A",
       "B"
     ]
-  }
+  },
+  "param_order" => [
+    "text1", "text2", "select", "select", "textarea", "encoding"
+  ]
 }
index 1fd9cff..5461aa5 100644 (file)
@@ -4,5 +4,8 @@
   "param" => {
     "one" => "foo",
     "two" => "bar"
-  }
+  },
+  "param_order" => [
+    "one", "two"
+  ],
 }
index 574091d..0fd5ba2 100644 (file)
@@ -10,5 +10,8 @@
       "A",
       "B"
     ]
-  }
+  },
+  "param_order" => [
+    "text1", "text2", "select", "select", "textarea", "encoding"
+  ]
 }
index 1fd9cff..1cd75c1 100644 (file)
@@ -4,5 +4,8 @@
   "param" => {
     "one" => "foo",
     "two" => "bar"
-  }
+  },
+  "param_order" => [
+    "one", "two"
+  ]
 }
index 1fd9cff..1cd75c1 100644 (file)
@@ -4,5 +4,8 @@
   "param" => {
     "one" => "foo",
     "two" => "bar"
-  }
+  },
+  "param_order" => [
+    "one", "two"
+  ]
 }
index c44c760..1a13c7e 100644 (file)
@@ -4,5 +4,8 @@
   "param" => {
     "one" => "foo",
     "two" => "bar=bam"
-  }
+  },
+  "param_order" => [
+    "one", "two"
+  ]
 }
index 6b87330..577f7a5 100644 (file)
@@ -21,5 +21,8 @@
   "param" => {
     "XForms:Model" => "<model><data1>asdfg</data1><data2>asdfg</data2></model>"
   },
+  param_order => [
+    "XForms:Model"
+  ],
   "start" => "asdfg\@asdfg.com"
 }
index a55b4b6..f0a53df 100644 (file)
@@ -3,5 +3,8 @@
   "upload" => {},
   "param" => {
     "XForms:Model" => "<model><data1>asdfg</data1><data2>asdfg</data2></model>"
-  }
+  },
+  param_order => [
+    "XForms:Model"
+  ]
 }