diff options
author | Jesse Luehrs <doy@tozt.net> | 2012-07-17 16:40:17 -0500 |
---|---|---|
committer | Jesse Luehrs <doy@tozt.net> | 2012-07-17 16:40:17 -0500 |
commit | ea9c268e1272d15f3ac0694b7fa91670294055c7 (patch) | |
tree | 8b35b8ae450fa3d513acb9f0b9cac0fa9698b99e | |
parent | ce39d07593b33d11ce990144e2c6155e4f302988 (diff) | |
download | web-request-ea9c268e1272d15f3ac0694b7fa91670294055c7.tar.gz web-request-ea9c268e1272d15f3ac0694b7fa91670294055c7.zip |
add encoding support
-rw-r--r-- | lib/Web/Request.pm | 26 |
1 files changed, 24 insertions, 2 deletions
diff --git a/lib/Web/Request.pm b/lib/Web/Request.pm index c4237db..ec788ea 100644 --- a/lib/Web/Request.pm +++ b/lib/Web/Request.pm @@ -1,6 +1,7 @@ package Web::Request; use Moose; +use Encode (); use HTTP::Headers; use URI; @@ -73,7 +74,14 @@ has query_parameters => ( is => 'ro', isa => 'HashRef[Str]', lazy => 1, - default => sub { +{ shift->uri->query_form } }, + default => sub { + my $self = shift; + + my %params = $self->uri->query_form; + return { + map { $_ => $self->decode($params{$_}) } keys %params + }; + }, ); has all_query_parameters => ( @@ -88,7 +96,7 @@ has all_query_parameters => ( my $ret = {}; while (my ($k, $v) = $it->()) { - push @{ $ret->{$k} ||= [] }, $v; + push @{ $ret->{$k} ||= [] }, $self->decode($v); } return $ret; @@ -122,6 +130,20 @@ has uploads => ( }, ); +has encoding => ( + is => 'ro', + isa => 'Str', + default => 'iso-8859-1', +); + +has _encoding_obj => ( + is => 'ro', + isa => 'Encode::Encoding', + lazy => 1, + default => sub { Encode::find_encoding(shift->encoding) }, + handles => ['decode', 'encode'], +); + sub new_from_env { my $class = shift; my ($env) = @_; |