blib/lib/Langertha/Role/Models.pm

filter: Statementstmt 66.6% 20 / 30 Branchbran 25.0% 1 / 4 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 66.6% 6 / 9 Podpod 100% 2 / 2 totaltotal 64.4% 29 / 45 CC 3 SCAR 6.5
CC
3
Cov
62%
_build_models
3.4
_build_models
3.4
_build_model
1.1
CRAP 1.9
« blib/lib/Langertha/Engine/AnthropicBase.pm ↑ Summary blib/lib/Langertha/Engine/NousResearch.pm »
1 package Langertha::Role::Models;
2 # ABSTRACT: Role for APIs with several models
3 193 our $VERSION = '0.505';
4 193 ▶use Moose::Role;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 193 requires qw(
7 default_model
8 );
9  
10 193 has models => (
11 is => 'rw',
12 isa => 'ArrayRef[Str]',
13 lazy_build => 1,
14 );
15 2 ▶sub _build_models {
Subroutine _build_models: called CC=2 SCAR=12.2
16 0 ▶ my ( $self ) = @_;
Subroutine _build_models: not called CC=2 SCAR=12.2
17 0 ▶ return $self->list_models() if $self->can('list_models');
Branch: 2 branches
BranchTrueFalseTotal
if $self->can("list_models") 2 0 2
if $self->can("list_models") 0 0 0
18 0 return [ $self->model ];
19 }
20  
21  
22 193 has model => (
23 is => 'ro',
24 isa => 'Maybe[Str]',
25 lazy_build => 1,
26 );
27 720 ▶sub _build_model {
Subroutine _build_model: called CC=1 SCAR=1.2
28 0 ▶ my ( $self ) = @_;
Subroutine _build_model: not called CC=1 SCAR=1.2
29 0 return $self->default_model;
30 }
31  
32  
33 # Cache configuration
34 has models_cache_ttl => (
35 is => 'ro',
36 isa => 'Int',
37 4453 ▶ default => sub { 3600 }, # 1 hour default
Subroutine __ANON__: called CC=1 SCAR=0.0
38 193 );
39  
40  
41 has _models_cache => (
42 is => 'rw',
43 isa => 'HashRef',
44 4456 ▶ default => sub { {} },
Subroutine __ANON__: called CC=1 SCAR=0.0
45 193 traits => ['Hash'],
46 handles => {
47 _clear_models_cache => 'clear',
48 },
49 );
50  
51 # Public method to clear the cache
52 4 ▶sub clear_models_cache {
Subroutine clear_models_cache: called CC=1 SCAR=1.2
Pod documented
53 0 ▶ my ($self) = @_;
Subroutine clear_models_cache: not called CC=1 SCAR=1.2
Pod documented
54 0 $self->_clear_models_cache;
55 0 $self->clear_models; # the lazy models attribute rebuilds on next access
56 0 return;
57 }
58  
59  
60  
61 193 1;
62  
63 __END__
« blib/lib/Langertha/Engine/AnthropicBase.pm ↑ Summary blib/lib/Langertha/Engine/NousResearch.pm »