NAME

Context - request-local storage

SYNOPSIS

$ctx = Pinwheel::Context::get();
$ctx = Pinwheel::Context::get('template');

Pinwheel::Context::set(x => 'foo', y => 'bar', z => 42);
Pinwheel::Context::set('template', foo => 'bar', baz => 'bal');

Pinwheel::Context::reset();

DESCRIPTION

This module provides storage that can be completely emptied with a call to reset(). It is used by Controller to provide request-local storage for modules, and as the mechanism for sharing data between controllers and views.

Contexts are hashes (get returns a reference to a hash). Multiple contexts are supported by use of the optional NAMESPACE argument. Whenever NAMESPACE is omitted, it defaults to a value generated from the caller's package.

ROUTINES

get() or get(NAMESPACE)

Retrieves a context hash.

Examples:

my $ctx = Pinwheel::Context::get();
return $ctx->{action};

or

my $ctx = Pinwheel::Context::get('template');
return $ctx->{pagetitle};
set(VALUES) or set(NAMESPACE, VALUES)

Set one or more values in the context. The appropriate context is emptied, then filled with the given VALUES.

Examples:

Pinwheel::Context::set(x => 1, y => 42);

or

Pinwheel::Context::set('template', date => $date, message => $msg);
Pinwheel::Context::set('template', schedule => $schedule);
# 'date' and 'message' are now gone
reset()

Clears all the context information in all namespaces.

AUTHOR

A&M Network Publishing <DLAMNetPub@bbc.co.uk>