Skip to content

Instantly share code, notes, and snippets.

@nekoya
Created October 19, 2012 01:26
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save nekoya/3915751 to your computer and use it in GitHub Desktop.
Mouse/URI::Escape::XS based on Plack::Request
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