Langertha/Engine/Remote.pm

filter: Statementstmt 100% 22 / 22 Branchbran 100% 2 / 2 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 6 / 6 Podpod 100% 2 / 2 totaltotal 100% 32 / 32 CC 2 SCAR 2.5
CC
2
Cov
100%
_update_rate_limit
2.0
BEGIN
1.0
BEGIN
1.0
CRAP 1.3
« Langertha/Engine/Perplexity.pm ↑ Summary Langertha/Role/JSON.pm »
1 package Langertha::Engine::Remote;
2 # ABSTRACT: Base class for all remote engines
3 34 our $VERSION = '0.502';
4 34 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 34 ▶use Langertha::RateLimit;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 34 with map { 'Langertha::Role::'.$_ } qw(
9 JSON
10 HTTP
11 PluginHost
12 );
13  
14  
15 34 has '+url' => (
16 required => 1,
17 );
18  
19 34 has _last_rate_limit => (
20 is => 'rw',
21 isa => 'Maybe[Langertha::RateLimit]',
22 predicate => '_has_last_rate_limit',
23 clearer => '_clear_last_rate_limit',
24 init_arg => undef,
25 );
26  
27 sub rate_limit {
28 8 ▶ my ( $self ) = @_;
Subroutine rate_limit: called CC=1 SCAR=0.0
Pod documented
29 8 return $self->_last_rate_limit;
30 }
31  
32  
33 sub has_rate_limit {
34 7 ▶ my ( $self ) = @_;
Subroutine has_rate_limit: called CC=1 SCAR=0.0
Pod documented
35 7 return defined $self->_last_rate_limit;
36 }
37  
38  
39 sub _update_rate_limit {
40 56 ▶ my ( $self, $http_response ) = @_;
Subroutine _update_rate_limit: called CC=2 SCAR=6.9
41 56 my $rl = $self->_parse_rate_limit_headers($http_response);
42 56 ▶ if ($rl) {
Branch: 1 branch
BranchTrueFalseTotal
if ($rl) 6 50 56
43 6 $self->_last_rate_limit($rl);
44 }
45 }
46  
47 sub _parse_rate_limit_headers {
48 14 ▶ return undef;
Subroutine _parse_rate_limit_headers: called CC=1 SCAR=0.0
49 }
50  
51 34 __PACKAGE__->meta->make_immutable;
52  
53  
54 34 1;
55  
56 __END__
57  
58 =pod
59  
60 =encoding UTF-8
61  
62 =head1 NAME
63  
64 Langertha::Engine::Remote - Base class for all remote engines
65  
66 =head1 VERSION
67  
68 version 0.502
69  
70 =head1 SYNOPSIS
71  
72 package My::Engine;
73 use Moose;
74  
75 extends 'Langertha::Engine::Remote';
76  
77 has '+url' => ( default => 'https://api.example.com' );
78  
79 sub default_model { 'my-model' }
80  
81 =head1 DESCRIPTION
82  
83 Root base class for all HTTP-based LLM engines in Langertha. Composes
84 L<Langertha::Role::JSON>, L<Langertha::Role::HTTP>, and
85 L<Langertha::Role::PluginHost>, and makes the C<url> attribute required.
86  
87 All engines in the distribution extend this class, either directly
88 (L<Langertha::Engine::Anthropic>, L<Langertha::Engine::Gemini>,
89 L<Langertha::Engine::Ollama>, L<Langertha::Engine::AKI>) or via the
90 OpenAI-compatible intermediate class L<Langertha::Engine::OpenAIBase>.
91  
92 =head2 rate_limit
93  
94 my $rl = $engine->rate_limit;
95  
96 Returns the L<Langertha::RateLimit> from the most recent API response,
97 or C<undef> if no rate limit headers were present.
98  
99 =head2 has_rate_limit
100  
101 if ($engine->has_rate_limit) { ... }
102  
103 Returns true if the engine has rate limit data from the most recent response.
104  
105 =head1 SEE ALSO
106  
107 =over
108  
109 =item * L<Langertha::Engine::OpenAIBase> - Intermediate base for all OpenAI-compatible engines
110  
111 =item * L<Langertha::Engine::Anthropic> - Anthropic Claude (extends this directly)
112  
113 =item * L<Langertha::Engine::Gemini> - Google Gemini (extends this directly)
114  
115 =item * L<Langertha::Engine::Ollama> - Ollama native API (extends this directly)
116  
117 =item * L<Langertha::Engine::AKI> - AKI EU engine (extends this directly)
118  
119 =item * L<Langertha::Role::HTTP> - HTTP transport with C<url>, C<user_agent>, request builders
120  
121 =item * L<Langertha::Role::JSON> - Shared JSON encoder/decoder
122  
123 =item * L<Langertha::Role::PluginHost> - Plugin system with lifecycle events
124  
125 =item * L<Langertha::RateLimit> - Rate limit data stored per-engine
126  
127 =back
128  
129 =head1 SUPPORT
130  
131 =head2 Issues
132  
133 Please report bugs and feature requests on GitHub at
134 L<https://github.com/Getty/langertha/issues>.
135  
136 =head2 IRC
137  
138 Join C<#langertha> on C<irc.perl.org> or message Getty directly.
139  
140 =head1 CONTRIBUTING
141  
142 Contributions are welcome! Please fork the repository and submit a pull request.
143  
144 =head1 AUTHOR
145  
146 Torsten Raudssus <getty@cpan.org>
147  
148 =head1 COPYRIGHT AND LICENSE
149  
150 This software is copyright (c) 2026 by Torsten Raudssus L<https://raudssus.de/>.
151  
152 This is free software; you can redistribute it and/or modify it under
153 the same terms as the Perl 5 programming language system itself.
154  
155 =cut
« Langertha/Engine/Perplexity.pm ↑ Summary Langertha/Role/JSON.pm »