Created
October 19, 2012 01:26
-
-
Save nekoya/3915751 to your computer and use it in GitHub Desktop.
Mouse/URI::Escape::XS based on Plack::Request
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package MyApp::Web::Request; | |
use Mouse; | |
use MouseX::Foreign qw(Plack::Request); | |
use URI::Escape::XS qw/uri_unescape/; | |
use Time::Piece; | |
has 'env' => ( is => 'rw', isa => 'HashRef', required => 1 ); | |
has 'now' => ( is => 'rw', isa => 'Time::Piece', default => sub { localtime } ); | |
has 'query_parameters' => ( | |
is => 'rw', | |
isa => 'HashRef', | |
lazy => 1, | |
default => sub { | |
my ($self) = @_; | |
my $p = {}; | |
my $query = $self->env->{QUERY_STRING} || ''; | |
$query =~ s/\+/ /g; | |
for my $q (split /&/, $query) { | |
my ($k, $v) = split /=/, $q; | |
$p->{ uri_unescape($k) } = uri_unescape($v); | |
} | |
$p; | |
}, | |
); | |
around BUILDARGS => sub { | |
my $orig = shift; | |
my $class = shift; | |
$class->$orig(env => $_[0]); | |
}; | |
no Mouse; | |
__PACKAGE__->meta->make_immutable; | |
1; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment