NAME
Klonk::Env - HTTP request environment
SYNOPSIS
use Klonk::Env;
my $env = Klonk::Env->new($psgi_env);
my $verb = $env->{REQUEST_METHOD};
my $q = $env->qparam('q');
my $name = $env->bparam('name');
my $path_to_foo = $env->vpath('/foo');
DESCRIPTION
This class extends a PSGI environment with some helper methods. All PSGI environment keys are still present and can be accessed by treating the object as a hash.
Constructor
Methods
$env->qparam($key)
-
Returns the value of the
$key
query ("GET") parameter in the request represented by$env
orundef
if there is no such parameter. If there are multiple parameters named$key
, the last one wins. Strings are automatically decoded from UTF-8. $env->bparam($key)
-
Returns the value of the
$key
body ("POST") parameter in the request represented by$env
orundef
if there is no such parameter. If there are multiple parameters named$key
, the last one wins. Strings are automatically decoded from UTF-8.Currently, only
application/x-www-form-urlencoded
bodies are supported and their size is limited to 10 MiB. $env->vpath($path)
-
Translates from app-internal to external resource paths. That is, if you have a resource at the (internal) path
/foo
, but your whole web application is mounted at/some/app
, then links to that resource that you hand out to clients need to prepend the application path in order to resolve.vpath
handles this translation:my $external_path = $env->vpath('/foo'); # returns "/some/app/foo"