NAME

Langertha::Knarr::Handler::Code - Coderef-backed Knarr handler for fakes, tests, and custom logic

VERSION

version 1.001

SYNOPSIS

use Langertha::Knarr::Handler::Code;

my $handler = Langertha::Knarr::Handler::Code->new(
    code => sub {
        my ($session, $request) = @_;
        return 'echo: ' . $request->messages->[-1]{content};
    },
    stream_code => sub {
        my @parts = ('hel', 'lo');
        return sub { @parts ? shift @parts : undef };
    },
);

DESCRIPTION

The simplest possible handler: pass coderefs that return strings (or chunk generators for streaming) and you get a working Knarr handler. Useful for tests, fakes, smoketests, and "fake LLM" demos.

code

Required. Coderef called as $code->($session, $request) for non-streaming requests; must return a scalar string.

stream_code

Optional. Coderef returning another coderef that yields the next chunk per call, undef to signal end.

models

Optional. Arrayref of model descriptors. Defaults to a single steerboard-code entry.

SUPPORT

Issues

Please report bugs and feature requests on GitHub at https://github.com/Getty/langertha-knarr/issues.

IRC

Join #langertha on irc.perl.org or message Getty directly.

CONTRIBUTING

Contributions are welcome! Please fork the repository and submit a pull request.

AUTHOR

Torsten Raudssus <torsten@raudssus.de> https://raudssus.de/

COPYRIGHT AND LICENSE

This software is copyright (c) 2026 by Torsten Raudssus.

This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.