File Coverage

blib/lib/PAGI/Middleware/Session/Store.pm
Criterion Covered Total %
statement 14 14 100.0
branch n/a
condition n/a
subroutine 6 6 100.0
pod 4 4 100.0
total 24 24 100.0


line stmt bran cond sub pod time code
1             package PAGI::Middleware::Session::Store;
2             $PAGI::Middleware::Session::Store::VERSION = '0.002000';
3 3     3   212306 use strict;
  3         6  
  3         117  
4 3     3   15 use warnings;
  3         11  
  3         731  
5              
6             =encoding UTF-8
7              
8             =head1 NAME
9              
10             PAGI::Middleware::Session::Store - Base class for async session storage
11              
12             =head1 SYNOPSIS
13              
14             package My::Store;
15             use parent 'PAGI::Middleware::Session::Store';
16             use Future;
17              
18             sub get {
19             my ($self, $id) = @_;
20             # Return Future resolving to hashref or undef
21             }
22              
23             sub set {
24             my ($self, $id, $data) = @_;
25             # Return Future resolving to the transport value
26             }
27              
28             sub delete {
29             my ($self, $id) = @_;
30             # Return Future resolving to 1
31             }
32              
33             =head1 DESCRIPTION
34              
35             PAGI::Middleware::Session::Store defines the async interface for session
36             storage backends. All methods return L objects so that storage
37             operations can be asynchronous (e.g. Redis, database).
38              
39             Subclasses must implement C, C, and C.
40              
41             =head1 METHODS
42              
43             =head2 new
44              
45             my $store = PAGI::Middleware::Session::Store->new(%options);
46              
47             Create a new store instance.
48              
49             =cut
50              
51             sub new {
52 21     21 1 204330 my ($class, %options) = @_;
53              
54 21         68 return bless { %options }, $class;
55             }
56              
57             =head2 get
58              
59             my $future = $store->get($id);
60              
61             Retrieve session data for the given ID. Returns a Future that resolves
62             to a hashref of session data, or undef if no session exists for that ID.
63             Subclasses must implement this.
64              
65             =cut
66              
67             sub get {
68 1     1 1 23 my ($self, $id) = @_;
69              
70 1         9 die ref($self) . " must implement get()";
71             }
72              
73             =head2 set
74              
75             my $future = $store->set($id, $data);
76              
77             Store session data for the given ID. Returns a Future that resolves to
78             the B — the opaque token the session middleware hands to
79             the State handler to send to the client. For server-side stores this is the
80             session ID (unchanged from the C<$id> argument); for cookie stores it is the
81             encoded session blob. Subclasses must implement this.
82              
83             =cut
84              
85             sub set {
86 1     1 1 18 my ($self, $id, $data) = @_;
87              
88 1         8 die ref($self) . " must implement set()";
89             }
90              
91             =head2 delete
92              
93             my $future = $store->delete($id);
94              
95             Remove session data for the given ID. Returns a Future that resolves to 1
96             on success. Subclasses must implement this.
97              
98             =cut
99              
100             sub delete {
101 1     1 1 17 my ($self, $id) = @_;
102              
103 1         8 die ref($self) . " must implement delete()";
104             }
105              
106             1;
107              
108             __END__