NAME
PAGI::Middleware::Session::State::Callback - Custom coderef-based session ID transport
SYNOPSIS
use PAGI::Middleware::Session::State::Callback;
my $state = PAGI::Middleware::Session::State::Callback->new(
extract => sub {
my ($scope) = @_;
# Return session ID or undef
return $scope->{headers}[0][1];
},
inject => sub {
my ($headers, $id, $options) = @_;
push @$headers, ['X-Session-ID', $id];
},
);
# Extract session ID from request
my $id = $state->extract($scope);
DESCRIPTION
Implements the PAGI::Middleware::Session::State interface using custom coderefs for session ID extraction and injection. This allows callers to define arbitrary session ID transport without writing a subclass.
CONFIGURATION
extract (required)
A coderef that receives
($scope)and returns the session ID or undef.inject (optional)
A coderef that receives
(\@headers, $id, \%options)and modifies the response headers. Defaults to a no-op if not provided.clear (optional)
A coderef that receives
(\@headers)and clears the client-side session state. Called when a session is destroyed. Defaults to a no-op if not provided.
extract
my $session_id = $state->extract($scope);
Calls the configured extract coderef with $scope and returns its result.
inject
$state->inject(\@headers, $id, \%options);
Calls the configured inject coderef with (\@headers, $id, \%options) if one was provided. Otherwise does nothing.
clear
$state->clear(\@headers);
Calls the configured clear coderef with (\@headers) if one was provided. Otherwise does nothing.
SEE ALSO
PAGI::Middleware::Session::State - Base state interface
PAGI::Middleware::Session::State::Cookie - Cookie-based session IDs
PAGI::Middleware::Session - Session management middleware