blib/lib/Langertha/PromptCache.pm

filter: Statementstmt 72.7% 24 / 33 Branchbran 31.2% 5 / 16 Conditioncond 14.2% 2 / 14 MC/DCmcdc 0.0% 0 / 8 Subroutinesub 70.0% 7 / 10 Podpod 100% 6 / 6 totaltotal 50.5% 44 / 87 CC 15 SCAR 18.2
CC
15
Cov
49%
to
10.0
to
10.0
to_openai
5.9
CRAP 6.2
« blib/lib/Langertha/Role/ResponseSize.pm ↑ Summary blib/lib/Langertha/Metrics.pm »
1 package Langertha::PromptCache;
2 # ABSTRACT: Immutable prompt-caching request control with cross-provider conversion
3 171 our $VERSION = '0.505';
4 171 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 171 ▶use Carp qw( croak );
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7  
8 171 has enable => (
9 is => 'ro',
10 isa => 'Bool',
11 default => 0,
12 );
13  
14  
15 has ttl => (
16 is => 'ro',
17 isa => 'Maybe[Str]',
18 19 ▶ default => sub { undef },
Subroutine __ANON__: called CC=1 SCAR=0.0
19 171 );
20  
21  
22 has key => (
23 is => 'ro',
24 isa => 'Maybe[Str]',
25 9 ▶ default => sub { undef },
Subroutine __ANON__: called CC=1 SCAR=0.0
26 171 );
27  
28  
29 9 ▶sub to_anthropic {
Subroutine to_anthropic: called CC=3 SCAR=15.4
Pod documented
30 0 ▶ my ( $self ) = @_;
Subroutine to_anthropic: not called CC=3 SCAR=15.4
Pod documented
31 0 ▶ return () unless $self->enable;
Branch: 2 branches
BranchTrueFalseTotal
unless $self->enable 0 9 9
unless $self->enable 0 0 0
32 return (
33 0 ▶ cache_control => {
Branch: 2 branches
BranchTrueFalseTotal
defined $self->ttl ? : 1 8 9
defined $self->ttl ? : 0 0 0
34 type => 'ephemeral',
35 ( defined $self->ttl ? ( ttl => $self->ttl ) : () ),
36 },
37 );
38 }
39  
40  
41 11 ▶sub to_openai {
Subroutine to_openai: called CC=3 SCAR=17.8
Pod documented
42 0 ▶ my ( $self ) = @_;
Subroutine to_openai: not called CC=3 SCAR=17.8
Pod documented
43 0 ▶ return () unless defined $self->key && length $self->key;
Branch: 2 branches
BranchTrueFalseTotal
unless defined $self->key and length $self->key 0 11 11
unless defined $self->key and length $self->key 0 0 0
Condition16%1/6
defined $self->key and length $self->key
!ll&&!rl&&r
0011
defined $self->key and length $self->key
!ll&&!rl&&r
000
MC/DC0%0/2
defined $self->key and length $self->key
defined $self->key length $self->key
MC/DC0%0/2
defined $self->key and length $self->key
defined $self->key length $self->key
Truth table33%1/3
A and B
A= defined $self->keyB= length $self->key
ABresult
0X0
100
111
Truth table0%0/3
A and B
A= defined $self->keyB= length $self->key
ABresult
0X0
100
111
44 0 return ( prompt_cache_key => $self->key );
45 }
46  
47  
48 # Maps a cache_wire_format tag to the per-format serializer method.
49 171 my %TO_METHOD = (
50 openai => 'to_openai',
51 anthropic => 'to_anthropic',
52 );
53  
54 20 ▶sub to {
Subroutine to: called CC=4 SCAR=23.1
Pod documented
55 0 ▶ my ( $self, $fmt ) = @_;
Subroutine to: not called CC=4 SCAR=23.1
Pod documented
56 0 ▶ my $method = $TO_METHOD{ $fmt // '' }
Branch: 2 branches
BranchTrueFalseTotal
my $method = $TO_METHOD{$fmt // ""} or croak(q[Langertha::PromptCache: unknown cache wire format '] . ($fmt // "") . q[']) 20 0 20
my $method = $TO_METHOD{$fmt // ""} or croak(q[Langertha::PromptCache: unknown cache wire format '] . ($fmt // "") . q[']) 0 0 0
Condition12%1/8
$fmt // ""
l!l
200
$fmt // ""
l!l
00
$fmt // ""
l!l
00
$fmt // ""
l!l
00
MC/DC0%0/1
$fmt // ""
$fmt
MC/DC0%0/1
$fmt // ""
$fmt
MC/DC0%0/1
$fmt // ""
$fmt
MC/DC0%0/1
$fmt // ""
$fmt
Truth table50%1/2
A
A= $fmt
Aresult
11
00
Truth table0%0/2
A
A= $fmt
Aresult
11
00
Truth table0%0/2
A
A= $fmt
Aresult
11
00
Truth table0%0/2
A
A= $fmt
Aresult
11
00
57 or croak "Langertha::PromptCache: unknown cache wire format '" . ( $fmt // '' ) . "'";
58 0 return $self->$method;
59 }
60  
61  
62 171 __PACKAGE__->meta->make_immutable;
63  
64  
65 171 1;
66  
67 __END__
« blib/lib/Langertha/Role/ResponseSize.pm ↑ Summary blib/lib/Langertha/Metrics.pm »