blib/lib/Langertha/Knarr/Session.pm

filter: Statementstmt 100% 21 / 21 Branchbran n/a Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 8 / 8 Podpod 100% 1 / 1 totaltotal 100% 30 / 30 CC 1 SCAR 0.0
CC
1
Cov
100%
BEGIN
1.0
BEGIN
1.0
__ANON__
1.0
CRAP 1.0
« bin/knarr ↑ Summary
1 package Langertha::Knarr::Session;
2 # ABSTRACT: Per-conversation state for a Knarr server
3 63 our $VERSION = '1.102';
4 63 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 63 ▶use Time::HiRes qw( time );
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7  
8 63 has id => (
9 is => 'ro',
10 isa => 'Str',
11 required => 1,
12 );
13  
14 has messages => (
15 is => 'rw',
16 isa => 'ArrayRef',
17 516 ▶ default => sub { [] },
Subroutine __ANON__: called CC=1 SCAR=0.0
18 63 );
19  
20 has metadata => (
21 is => 'rw',
22 isa => 'HashRef',
23 516 ▶ default => sub { {} },
Subroutine __ANON__: called CC=1 SCAR=0.0
24 63 );
25  
26 has handler_state => (
27 is => 'rw',
28 isa => 'HashRef',
29 516 ▶ default => sub { {} },
Subroutine __ANON__: called CC=1 SCAR=0.0
30 63 );
31  
32 has created_at => (
33 is => 'ro',
34 isa => 'Num',
35 516 ▶ default => sub { time() },
Subroutine __ANON__: called CC=1 SCAR=0.0
36 63 );
37  
38 has last_active => (
39 is => 'rw',
40 isa => 'Num',
41 516 ▶ default => sub { time() },
Subroutine __ANON__: called CC=1 SCAR=0.0
42 63 );
43  
44 526 ▶sub touch { $_[0]->last_active( time() ) }
Subroutine touch: called CC=1 SCAR=0.0
Pod documented
45  
46 63 __PACKAGE__->meta->make_immutable;
47 63 1;
48  
49 __END__
50  
51 =pod
52  
53 =encoding UTF-8
54  
55 =head1 NAME
56  
57 Langertha::Knarr::Session - Per-conversation state for a Knarr server
58  
59 =head1 VERSION
60  
61 version 1.102
62  
63 =head1 DESCRIPTION
64  
65 Per-conversation state object that Knarr passes to handlers. Sessions
66 are created on demand by the Knarr core (one per unique session id
67 seen in incoming requests) and reused across multiple turns. Handlers
68 that need to remember state across turns store it in
69 L</handler_state>; for example L<Langertha::Knarr::Handler::Raider>
70 caches its per-session L<Langertha::Raider> instance there.
71  
72 =head2 id
73  
74 Required. The unique session id, typically supplied by the client via
75 the C<x-session-id> header or extracted from a protocol-specific field.
76  
77 =head2 messages
78  
79 ArrayRef of message hashes, free-form for handlers that want to keep
80 their own conversation history (most don't — Raider keeps its own).
81  
82 =head2 metadata
83  
84 HashRef for arbitrary per-session tags. Handlers and middlewares can
85 read or write this without coordinating with each other.
86  
87 =head2 handler_state
88  
89 HashRef where decorator handlers can stash per-session state without
90 colliding with each other. Convention: key by handler class name.
91  
92 =head2 created_at
93  
94 Numeric epoch seconds when the session was first seen.
95  
96 =head2 last_active
97  
98 Numeric epoch seconds, updated by L</touch> on every request.
99  
100 =head2 touch
101  
102 Updates L</last_active> to the current time. Called by the Knarr core
103 on every dispatch.
104  
105 =head1 SUPPORT
106  
107 =head2 Issues
108  
109 Please report bugs and feature requests on GitHub at
110 L<https://github.com/Getty/langertha-knarr/issues>.
111  
112 =head2 IRC
113  
114 Join C<#langertha> on C<irc.perl.org> or message Getty directly.
115  
116 =head1 CONTRIBUTING
117  
118 Contributions are welcome! Please fork the repository and submit a pull request.
119  
120 =head1 AUTHOR
121  
122 Torsten Raudssus <torsten@raudssus.de> L<https://raudssus.de/>
123  
124 =head1 COPYRIGHT AND LICENSE
125  
126 This software is copyright (c) 2026 by Torsten Raudssus.
127  
128 This is free software; you can redistribute it and/or modify it under
129 the same terms as the Perl 5 programming language system itself.
130  
131 =cut
« bin/knarr ↑ Summary