blib/lib/PAGI/Middleware/Session/Store/Memory.pm

filter: Statementstmt 100% 24 / 24 Branchbran n/a Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 8 / 8 Podpod 100% 4 / 4 totaltotal 100% 36 / 36 CC 1 SCAR 0.0
CC
1
Cov
100%
BEGIN
1.0
BEGIN
1.0
BEGIN
1.0
CRAP 1.0
« blib/lib/PAGI/Middleware/Session/Store.pm ↑ Summary blib/lib/PAGI/Tools.pm »
1 package PAGI::Middleware::Session::Store::Memory;
2 3 $PAGI::Middleware::Session::Store::Memory::VERSION = '0.002002';
3 3 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 3 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 3 ▶use parent 'PAGI::Middleware::Session::Store';
Subroutine BEGIN: called CC=1 SCAR=0.0
6 3 ▶use Future;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 =head1 NAME
9  
10 PAGI::Middleware::Session::Store::Memory - In-memory session store
11  
12 =head1 SYNOPSIS
13  
14 use PAGI::Middleware::Session::Store::Memory;
15  
16 my $store = PAGI::Middleware::Session::Store::Memory->new();
17  
18 # All methods return Futures
19 await $store->set('session_id', { user_id => 123 });
20 my $data = await $store->get('session_id');
21 await $store->delete('session_id');
22  
23 # For testing
24 PAGI::Middleware::Session::Store::Memory->clear_all();
25  
26 =head1 DESCRIPTION
27  
28 Implements the L<PAGI::Middleware::Session::Store> interface using a
29 package-level hash. Sessions are shared across all instances within the
30 same process but are not shared between workers and are lost on restart.
31  
32 B<Warning:> This store is suitable for development and single-process
33 deployments only. For production multi-worker deployments, use a store
34 backed by Redis, a database, or another shared storage.
35  
36 =cut
37  
38 3 my %sessions;
39  
40 =head1 METHODS
41  
42 =head2 get
43  
44 my $future = $store->get($id);
45  
46 Returns a Future resolving to the session hashref, or undef if no
47 session exists for the given ID.
48  
49 =cut
50  
51 27 ▶sub get {
Subroutine get: called CC=1 SCAR=0.0
Pod documented
52 27 my ($self, $id) = @_;
53  
54 27 return Future->done($sessions{$id});
55 }
56  
57 =head2 set
58  
59 my $future = $store->set($id, $data);
60  
61 Stores the session data hashref under the given ID. Returns a Future
62 resolving to the transport value (the session ID for server-side stores,
63 or encoded data for cookie stores).
64  
65 =cut
66  
67 38 ▶sub set {
Subroutine set: called CC=1 SCAR=0.0
Pod documented
68 38 my ($self, $id, $data) = @_;
69  
70 38 $sessions{$id} = $data;
71 38 return Future->done($id);
72 }
73  
74 =head2 delete
75  
76 my $future = $store->delete($id);
77  
78 Removes the session for the given ID. Returns a Future resolving to 1.
79  
80 =cut
81  
82 5 ▶sub delete {
Subroutine delete: called CC=1 SCAR=0.0
Pod documented
83 5 my ($self, $id) = @_;
84  
85 5 delete $sessions{$id};
86 5 return Future->done(1);
87 }
88  
89 =head2 clear_all
90  
91 PAGI::Middleware::Session::Store::Memory->clear_all();
92  
93 Class method that removes all sessions from the in-memory store.
94 Useful for test cleanup.
95  
96 =cut
97  
98 28 ▶sub clear_all {
Subroutine clear_all: called CC=1 SCAR=0.0
Pod documented
99 28 %sessions = ();
100 }
101  
102 3 1;
103  
104 __END__
« blib/lib/PAGI/Middleware/Session/Store.pm ↑ Summary blib/lib/PAGI/Tools.pm »