Stefan G. > Kelp-0.455 > Kelp::Request

Download:
Kelp-0.455.tar.gz

Dependencies

Annotate this POD

Website

CPAN RT

Open  0
View/Report Bugs
Source   Latest Release: Kelp-0.9015

NAME ^

Kelp::Request - Request class for a Kelp application

SYNOPSIS ^

    my $request = Kelp::Request( app => $app, env => $env );

DESCRIPTION ^

This module provides a convenience layer on top of Plack::Request. It extends it to add several convenience methods.

ATTRIBUTES ^

app

A reference to the Kelp application.

stash

An all use, utility hash to use to pass information between routes.

named

This hash is initialized with the named placeholders of the path that the current route is processing.

param

Returns the HTTP parameters of the request. This method delegates all the work to "param" in Plack::Request, except when the content type of the request is application/json. In that case, it will decode the JSON body and return as follows:

session

Returns the Plack session hash or dies if no Session middleware was included.

    sub route_zero {
        my $self = shift;
        $self->session->{user} = 45;
    }

If called with a single argument, returns that value from the session hash:

    sub route_one {
        my $self = shift;
        my $user = $self->req->session('user');
    }

Set values in the session using key-value pairs:

    sub route_two {
        my $self = shift;
        $self->req->session(
            name  => 'Jill Andrews',
            age   => 24,
            email => 'jill@perlkelp.com'
        );
    }

Common tasks with sessions

Initialize file sessions

In your config file:

    middleware => ['Session'],
    middleware_init => {
        Session => {
            store => 'File'
        }
    }
Delete session values
    delete $self->req->session->{'useless'};
Remove all session values
    $self->req->session = {};

is_ajax

Returns true if the request was called with XMLHttpRequest.

is_json

Returns true if the request's content type was application/json.

syntax highlighting: