« blib/lib/Langertha/Knarr/CLI/Role/GlobalOptions.pm
↑ Summary
blib/lib/Langertha/Knarr/Handler.pm »
| 1 | package Langertha::Knarr::Handler::Code; | ||||||||||||||||||||||||
| 2 | # ABSTRACT: Coderef-backed Knarr handler for fakes, tests, and custom logic | ||||||||||||||||||||||||
| 3 | 7 | our $VERSION = '1.103'; | |||||||||||||||||||||||
| 4 | 7 | ▶ | use Moose; | ||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||
| 5 | 7 | ▶ | use Future; | ||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||
| 6 | 7 | ▶ | use Future::AsyncAwait; | ||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||
| 7 | 7 | ▶ | use Langertha::Knarr::Stream; | ||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||
| 8 | 7 | ▶ | use Langertha::Knarr::Response; | ||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||
| 10 | 7 | with 'Langertha::Knarr::Handler'; | |||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||
| 13 | 7 | has code => ( | |||||||||||||||||||||||
| 14 | is => 'ro', | ||||||||||||||||||||||||
| 15 | isa => 'CodeRef', | ||||||||||||||||||||||||
| 16 | required => 1, | ||||||||||||||||||||||||
| 17 | ); | ||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||
| 19 | # Optional: separate generator for streaming. Returns a coderef that itself | ||||||||||||||||||||||||
| 20 | # returns next-chunk strings (undef = done) when called. | ||||||||||||||||||||||||
| 21 | has stream_code => ( | ||||||||||||||||||||||||
| 22 | is => 'ro', | ||||||||||||||||||||||||
| 23 | isa => 'Maybe[CodeRef]', | ||||||||||||||||||||||||
| 24 | 14 | ▶ | default => sub { undef }, | ||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||
| 25 | 7 | ); | |||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||
| 27 | has models => ( | ||||||||||||||||||||||||
| 28 | is => 'ro', | ||||||||||||||||||||||||
| 29 | isa => 'ArrayRef', | ||||||||||||||||||||||||
| 30 | 18 | ▶ | default => sub { [ { id => 'knarr-code', object => 'model' } ] }, | ||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||
| 31 | 7 | ); | |||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||
| 33 | 13 | ▶ | async sub handle_chat_f { | ||||||||||||||||||||||
|
Subroutine
handle_chat_f: called CC=3 SCAR=11.2
Pod
undocumented
| |||||||||||||||||||||||||
| 34 | 13 | my ($self, $session, $request) = @_; | |||||||||||||||||||||||
| 35 | 13 | my $out = $self->code->( $session, $request ); | |||||||||||||||||||||||
| 36 | 12 | my $r = Langertha::Knarr::Response->coerce($out); | |||||||||||||||||||||||
| 37 | 12 | ▶ | return $r->clone_with( model => $r->model // $request->model // 'knarr-code' ); | ||||||||||||||||||||||
|
Condition60%3/5
($r->model // $request->model) // "knarr-code"
$r->model // $request->model
MC/DC0%0/2
($r->model // $request->model) // "knarr-code"
$r->model
$request->model
Truth table66%2/3
A // B
A= $r->modelB= $request->model
| |||||||||||||||||||||||||
| 38 | 7 | } | |||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||
| 40 | 4 | ▶ | async sub handle_stream_f { | ||||||||||||||||||||||
|
Subroutine
handle_stream_f: called CC=2 SCAR=7.6
Pod
undocumented
| |||||||||||||||||||||||||
| 41 | 4 | my ($self, $session, $request) = @_; | |||||||||||||||||||||||
| 42 | 4 | ▶ | if ( my $sc = $self->stream_code ) { | ||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||
| 43 | 4 | my $gen = $sc->( $session, $request ); | |||||||||||||||||||||||
| 44 | 4 | return Langertha::Knarr::Stream->new( generator => $gen ); | |||||||||||||||||||||||
| 45 | } | ||||||||||||||||||||||||
| 46 | 0 | my $text = $self->code->( $session, $request ); | |||||||||||||||||||||||
| 47 | 0 | return Langertha::Knarr::Stream->from_list("$text"); | |||||||||||||||||||||||
| 48 | 7 | } | |||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||
| 50 | 1 | ▶ | sub list_models { $_[0]->models } | ||||||||||||||||||||||
|
Subroutine
list_models: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||
| 52 | 7 | __PACKAGE__->meta->make_immutable; | |||||||||||||||||||||||
| 53 | 7 | 1; | |||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||
| 55 | __END__ | ||||||||||||||||||||||||