Marquee Marquee::Context - Context

TABLE OF CONTENTS

NAME

Marquee::Context - Context

SYNOPSIS

my $c = Marquee::Context->new(app => $app, tx => $tx);
my $app             = $c->app;
my $req             = $c->req;
my $res             = $c->res;
my $tx              = $c->tx;
my $session         = $c->session;
my $cookie          = $c->cookie('key');
my $signed_cookie   = $c->signed_cookie('key');
my $stash           = $c->stash;

DESCRIPTION

Marquee::Context class represents a per request context. This also has ability to manage session and signed cookies.

ATTRIBUTES

Marquee::Context implements the following attributes.

app

Marquee application instance.

my $app = $c->app;

req

An Alias to $self->tx->req.

my $req = $c->req;
$c->req($req);

res

An Alias to $self->tx->res.

my $res = $c->req;
$c->req($res);

session

Persistent data storage, stored JSON serialized in a signed cookie. Note that cookies are generally limited to 4096 bytes of data.

my $session = $c->session;
my $foo     = $session->{'foo'};
$session->{foo} = 'bar';

session_path

A path for session. Defaults to /.

$c->session_path('/some/path/')
my $path = $c->session_path

session_secure

Set the secure flag on all session cookies, so that browsers send them only over HTTPS connections.

my $secure = $c->session_secure;
$c->session_secure(1);

session_expiration

Time for the session to expire in seconds from now, defaults to 3600. The expiration timeout gets refreshed for every request

my $time = $c->session_expiration;
$c->session_expiration(3600);

session_name

Name of the signed cookie used to store session data, defaults to 'mrqe'.

my $name = $c->session_name;
$c->session_name('session');

stash

A stash that inherits app's one.

my $stash = $c->stash;

tx

Mojo::Transaction instance.

my $tx = $c->tx;

CLASS METHODS

Marquee::Context implements the following class methods.

new

Constructor.

my $c = Marquee::Context->new;

INSTANCE METHODS

Marquee::Context implements the following instance methods.

close

Close the context.

my $c2 = $c->close;

cookie

my $value  = $c->cookie('foo');
my @values = $c->cookie('foo');
$c         = $c->cookie(foo => 'bar');
$c         = $c->cookie(foo => 'bar', {path => '/'});

Access request cookie values and create new response cookies.

# Create response cookie with domain
$c->cookie(name => 'sebastian', {domain => 'mojolicio.us'});

res

An alias for $c->tx->res

$c->tx->res($res);
$res = $c->tx->res;

req

An alias for $c->tx->req

$c->tx->res($req);
$req = $c->tx->res;

serve

An alias for $app->serve

$c->serve('path/to/index.html');

served

Check if the response code has already been set and returns boolean.

if (! $c->served) {
    ...
}

signed_cookie

Access signed request cookie values and create new signed response cookies. Cookies failing signature verification will be automatically discarded.

my $value  = $c->signed_cookie('foo');
my @values = $c->signed_cookie('foo');
$c         = $c->signed_cookie(foo => 'bar');
$c         = $c->signed_cookie(foo => 'bar', {path => '/'});

SEE ALSO

Marquee, Mojolicious