blib/lib/Langertha/CallResult.pm

filter: Statementstmt 64.7% 33 / 51 Branchbran 47.7% 21 / 44 Conditioncond 36.0% 18 / 50 MC/DCmcdc 25.0% 6 / 24 Subroutinesub 66.6% 4 / 6 Podpod 100% 4 / 4 totaltotal 48.0% 86 / 179 CC 41 SCAR 44.0
CC
41
Cov
50%
from_http_response
93.2
from_http_response
93.2
with_value
2.5
CRAP 81.3
« blib/lib/Langertha/Role/OpenAPI.pm ↑ Summary blib/lib/Langertha/ToolChoice.pm »
1 package Langertha::CallResult;
2 # ABSTRACT: Result of an embedding, transcription or image call, with usage, rate limit and timing
3 169 our $VERSION = '0.505';
4 169 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 169 ▶use Langertha::Usage;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7  
8 169 has value => (
9 is => 'ro',
10 required => 1,
11 );
12  
13  
14 169 has usage => (
15 is => 'ro',
16 isa => 'Langertha::Usage',
17 predicate => 'has_usage',
18 );
19  
20  
21 169 has rate_limit => (
22 is => 'ro',
23 isa => 'Langertha::RateLimit',
24 predicate => 'has_rate_limit',
25 );
26  
27  
28 169 has model => (
29 is => 'ro',
30 isa => 'Str',
31 predicate => 'has_model',
32 );
33  
34  
35 169 has total_seconds => (
36 is => 'ro',
37 isa => 'Num',
38 predicate => 'has_total_seconds',
39 );
40  
41  
42 169 has raw => (
43 is => 'ro',
44 isa => 'Ref',
45 predicate => 'has_raw',
46 );
47  
48  
49 28 ▶sub from_http_response {
Subroutine from_http_response: called CC=20 SCAR=45.3
Pod documented
50 0 ▶ my ( $class, $engine, $http_response, %args ) = @_;
Subroutine from_http_response: not called CC=20 SCAR=45.3
Pod documented
51 0 my $raw;
52 0 ▶ my $type = lc( $http_response->content_type // '' );
Condition25%1/4
$http_response->content_type // ""
l!l
280
$http_response->content_type // ""
l!l
00
MC/DC0%0/1
$http_response->content_type // ""
$http_response->content_type
MC/DC0%0/1
$http_response->content_type // ""
$http_response->content_type
Truth table50%1/2
A
A= $http_response->content_type
Aresult
11
00
Truth table0%0/2
A
A= $http_response->content_type
Aresult
11
00
53 0 ▶ if ( $type =~ /json/ || ( $type !~ m{\Atext/} && $http_response->content =~ /\A\s*[\{\[]/ ) ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($type =~ /json/ or not $type =~ m[\Atext/] and $http_response->content =~ /\A\s*[\{\[]/) 27 1 28
if ($type =~ /json/ or not $type =~ m[\Atext/] and $http_response->content =~ /\A\s*[\{\[]/) 0 0 0
Condition25%3/12
$type =~ /json/ or not $type =~ m[\Atext/] and $http_response->content =~ /\A\s*[\{\[]/
l!l&&r!l&&!r
2701
not $type =~ m[\Atext/] and $http_response->content =~ /\A\s*[\{\[]/
!ll&&!rl&&r
100
$type =~ /json/ or not $type =~ m[\Atext/] and $http_response->content =~ /\A\s*[\{\[]/
l!l&&r!l&&!r
000
not $type =~ m[\Atext/] and $http_response->content =~ /\A\s*[\{\[]/
!ll&&!rl&&r
000
MC/DC33%1/3
$type =~ /json/ or not $type =~ m[\Atext/] and $http_response->content =~ /\A\s*[\{\[]/
$type =~ /json/ not $type =~ m[\Atext/] $http_response->content =~ /\A\s*[\{\[]/
MC/DC0%0/3
$type =~ /json/ or not $type =~ m[\Atext/] and $http_response->content =~ /\A\s*[\{\[]/
$type =~ /json/ not $type =~ m[\Atext/] $http_response->content =~ /\A\s*[\{\[]/
Truth table50%2/4
A or not(B) and C
A= $type =~ /json/B= not $type =~ m[\Atext/]C= $http_response->content =~ /\A\s*[\{\[]/
ABCresult
1XX1
0111
00X0
0100
Truth table0%0/4
A or not(B) and C
A= $type =~ /json/B= not $type =~ m[\Atext/]C= $http_response->content =~ /\A\s*[\{\[]/
ABCresult
1XX1
0111
00X0
0100
54 0 local $@;
55 0 $raw = eval { $engine->json->decode( $http_response->content ) };
56 }
57 0 my $usage;
58 0 ▶ if ( ref $raw eq 'HASH' ) {
Branch: 2 branches
BranchTrueFalseTotal
if (ref $raw eq "HASH") 27 1 28
if (ref $raw eq "HASH") 0 0 0
59 0 my $block = $raw->{usage};
60 # A duration-billed transcription has no token counts; zeros would lie.
61 $usage = Langertha::Usage->from_raw($raw)
62 0 ▶ unless ref $block eq 'HASH' && ( $block->{type} // '' ) eq 'duration';
Branch: 2 branches
BranchTrueFalseTotal
unless ref $block eq "HASH" and ($block->{"type"} // "") eq "duration" 26 1 27
unless ref $block eq "HASH" and ($$block{"type"} // "") eq "duration" 0 0 0
Condition50%5/10
ref $block eq "HASH" and ($block->{"type"} // "") eq "duration"
!ll&&!rl&&r
6201
$block->{"type"} // ""
l!l
516
ref $block eq "HASH" and ($$block{"type"} // "") eq "duration"
!ll&&!rl&&r
000
$$block{"type"} // ""
l!l
00
MC/DC100%2/2
ref $block eq "HASH" and ($block->{"type"} // "") eq "duration"
ref $block eq "HASH" $block->{"type"}
MC/DC0%0/2
ref $block eq "HASH" and ($$block{"type"} // "") eq "duration"
ref $block eq "HASH" $$block{"type"}
Truth table100%3/3
A and B
A= ref $block eq "HASH"B= $block->{"type"}
ABresult
0X0
100
111
Truth table0%0/3
A and B
A= ref $block eq "HASH"B= $$block{"type"}
ABresult
0X0
100
111
63 }
64 my $model = ref $raw eq 'HASH' && defined $raw->{model} && !ref $raw->{model}
65 0 ▶ && length $raw->{model} ? $raw->{model} : $args{model};
Branch: 2 branches
BranchTrueFalseTotal
ref $raw eq 'HASH' && defined $raw->{'model'} && !ref($raw->{'model'}) && length $raw->{'model'} ? : 9 19 28
ref $raw eq 'HASH' && defined $$raw{'model'} && !ref($$raw{'model'}) && length $$raw{'model'} ? : 0 0 0
Condition38%7/18
ref $raw eq "HASH" and defined $raw->{"model"} and not ref $raw->{"model"} and length $raw->{"model"}
!ll&&!rl&&r
1909
ref $raw eq "HASH" and defined $raw->{"model"} and not ref $raw->{"model"}
!ll&&!rl&&r
1909
ref $raw eq "HASH" and defined $raw->{"model"}
!ll&&!rl&&r
1189
ref $raw eq "HASH" and defined $$raw{"model"} and not ref $$raw{"model"} and length $$raw{"model"}
!ll&&!rl&&r
000
ref $raw eq "HASH" and defined $$raw{"model"} and not ref $$raw{"model"}
!ll&&!rl&&r
000
ref $raw eq "HASH" and defined $$raw{"model"}
!ll&&!rl&&r
000
MC/DC50%2/4
ref $raw eq "HASH" and defined $raw->{"model"} and not ref $raw->{"model"} and length $raw->{"model"}
ref $raw eq "HASH" defined $raw->{"model"} not ref $raw->{"model"} length $raw->{"model"}
MC/DC0%0/4
ref $raw eq "HASH" and defined $$raw{"model"} and not ref $$raw{"model"} and length $$raw{"model"}
ref $raw eq "HASH" defined $$raw{"model"} not ref $$raw{"model"} length $$raw{"model"}
Truth table60%3/5
A and B and not(C) and D
A= ref $raw eq "HASH"B= defined $raw->{"model"}C= not ref $raw->{"model"}D= length $raw->{"model"}
ABCDresult
0XXX0
10XX0
110X0
11100
11111
Truth table0%0/5
A and B and not(C) and D
A= ref $raw eq "HASH"B= defined $$raw{"model"}C= not ref $$raw{"model"}D= length $$raw{"model"}
ABCDresult
0XXX0
10XX0
110X0
11100
11111
66 0 ▶ my $rate_limit = $engine->can('has_rate_limit') && $engine->has_rate_limit
Branch: 2 branches
BranchTrueFalseTotal
$engine->can('has_rate_limit') && $engine->has_rate_limit ? : 12 16 28
$engine->can('has_rate_limit') && $engine->has_rate_limit ? : 0 0 0
Condition33%2/6
$engine->can("has_rate_limit") and $engine->has_rate_limit
!ll&&!rl&&r
01612
$engine->can("has_rate_limit") and $engine->has_rate_limit
!ll&&!rl&&r
000
MC/DC50%1/2
$engine->can("has_rate_limit") and $engine->has_rate_limit
$engine->can("has_rate_limit") $engine->has_rate_limit
MC/DC0%0/2
$engine->can("has_rate_limit") and $engine->has_rate_limit
$engine->can("has_rate_limit") $engine->has_rate_limit
Truth table66%2/3
A and B
A= $engine->can("has_rate_limit")B= $engine->has_rate_limit
ABresult
0X0
100
111
Truth table0%0/3
A and B
A= $engine->can("has_rate_limit")B= $engine->has_rate_limit
ABresult
0X0
100
111
67 ? $engine->rate_limit : undef;
68 return $class->new(
69 value => $args{value},
70 defined $usage ? ( usage => $usage ) : (),
71 defined $rate_limit ? ( rate_limit => $rate_limit ) : (),
72 defined $model ? ( model => $model ) : (),
73 0 ▶ defined $args{total_seconds} ? ( total_seconds => $args{total_seconds} ) : (),
Branch: 10 branches
BranchTrueFalseTotal
defined $usage ? : 21 7 28
defined $rate_limit ? : 12 16 28
defined $model ? : 28 0 28
defined $args{'total_seconds'} ? : 27 1 28
defined $raw ? : 27 1 28
defined $usage ? : 0 0 0
defined $rate_limit ? : 0 0 0
defined $model ? : 0 0 0
defined $args{'total_seconds'} ? : 0 0 0
defined $raw ? : 0 0 0
74 defined $raw ? ( raw => $raw ) : (),
75 );
76 }
77  
78  
79 2 ▶sub with_value {
Subroutine with_value: called CC=2 SCAR=9.2
Pod documented
80 0 ▶ my ( $self, $value ) = @_;
Subroutine with_value: not called CC=2 SCAR=9.2
Pod documented
81 return $self->new(
82 value => $value,
83 0 ▶ map { my $has = "has_$_"; $self->$has ? ( $_ => $self->$_ ) : () }
Branch: 2 branches
BranchTrueFalseTotal
$self->$has ? : 8 2 10
$self->$has ? : 0 0 0
84 qw( usage rate_limit model total_seconds raw ),
85 );
86 }
87  
88  
89 169 __PACKAGE__->meta->make_immutable;
90  
91  
92 169 1;
93  
94 __END__
« blib/lib/Langertha/Role/OpenAPI.pm ↑ Summary blib/lib/Langertha/ToolChoice.pm »