| 1 | package Langertha::Knarr::Session; | ||
| 2 | # ABSTRACT: Per-conversation state for a Knarr server | ||
| 3 | 16 | our $VERSION = '1.100'; | |
| 4 | 16 | ▶ | use Moose; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 5 | 16 | ▶ | use Time::HiRes qw( time ); |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 6 | |||
| 7 | |||
| 8 | 16 | has id => ( | |
| 9 | is => 'ro', | ||
| 10 | isa => 'Str', | ||
| 11 | required => 1, | ||
| 12 | ); | ||
| 13 | |||
| 14 | has messages => ( | ||
| 15 | is => 'rw', | ||
| 16 | isa => 'ArrayRef', | ||
| 17 | 49 | ▶ | default => sub { [] }, |
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||
| 18 | 16 | ); | |
| 19 | |||
| 20 | has metadata => ( | ||
| 21 | is => 'rw', | ||
| 22 | isa => 'HashRef', | ||
| 23 | 49 | ▶ | default => sub { {} }, |
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||
| 24 | 16 | ); | |
| 25 | |||
| 26 | has handler_state => ( | ||
| 27 | is => 'rw', | ||
| 28 | isa => 'HashRef', | ||
| 29 | 49 | ▶ | default => sub { {} }, |
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||
| 30 | 16 | ); | |
| 31 | |||
| 32 | has created_at => ( | ||
| 33 | is => 'ro', | ||
| 34 | isa => 'Num', | ||
| 35 | 49 | ▶ | default => sub { time() }, |
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||
| 36 | 16 | ); | |
| 37 | |||
| 38 | has last_active => ( | ||
| 39 | is => 'rw', | ||
| 40 | isa => 'Num', | ||
| 41 | 49 | ▶ | default => sub { time() }, |
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||
| 42 | 16 | ); | |
| 43 | |||
| 44 | 40 | ▶ | sub touch { $_[0]->last_active( time() ) } |
|
Subroutine
touch: called CC=1 SCAR=0.0
Pod
documented
| |||
| 45 | |||
| 46 | 16 | __PACKAGE__->meta->make_immutable; | |
| 47 | 16 | 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.100 | ||
| 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 | ||