+#########################################################
+# private / internal methods and subs
+
+
+sub _mod_perl_args {
+ my ( $self, $apr ) = @_;
+ my %args;
+ if ($apr->isa('Apache::Request')) {
+ foreach my $key ( $apr->param ) {
+ my @values = $apr->param($key);
+ $args{$key} = @values == 1 ? $values[0] : \@values;
+ }
+ } else {
+ my $body = $self->_prepare_body($apr);
+ %args = %{$body->param};
+ my $uri = URI->new($self->ar->unparsed_uri);
+ foreach my $key ($uri->query_param) {
+ if (ref $args{$key}) {
+ push (@{$args{$key}}, $uri->query_param($key));
+ } else {
+ if ($args{$key}) {
+ $args{$key} = [ $args{$key}, $uri->query_param($key) ];
+ } else {
+ my @args = $uri->query_param($key);
+ if (scalar @args > 1) {
+ $args{$key} = [ $uri->query_param($key) ];
+ } else {
+ $args{$key} = $uri->query_param($key);
+ }
+ }
+ }
+ }
+ }
+ return %args;
+}
+
+sub _prepare_body {
+ my ( $self, $r ) = @_;
+
+ unless ($self->{__http_body}) {
+ my $content_type = $r->headers_in->get('Content-Type');
+ my $content_length = $r->headers_in->get('Content-Length');
+ my $body = HTTP::Body->new( $content_type, $content_length );
+ my $length = $content_length;
+ while ( $length ) {
+ $r->read( my $buffer, ( $length < 8192 ) ? $length : 8192 );
+ $length -= length($buffer);
+ $body->add($buffer);
+ }
+ $self->{__http_body} = $body;
+ }
+ return $self->{__http_body};
+}