blib/lib/Langertha/Manifest/Model.pm

filter: Statementstmt 97.5% 40 / 41 Branchbran 100% 14 / 14 Conditioncond 50.0% 3 / 6 MC/DCmcdc 33.3% 1 / 3 Subroutinesub 88.8% 8 / 9 Podpod 60.0% 3 / 5 totaltotal 88.4% 69 / 78 CC 11 SCAR 11.3
CC
11
Cov
93%
__ANON__
5.0
BUILD
4.2
supports
2.0
CRAP 3.1
« blib/lib/Langertha/Engine/VLLMHook.pm ↑ Summary blib/lib/Langertha/Engine/Cerebras.pm »
1 package Langertha::Manifest::Model;
2 # ABSTRACT: One model entry of a provider manifest: id, endpoint, declared capabilities
3 8 our $VERSION = '0.505';
4 8 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 8 ▶use JSON::MaybeXS ();
Subroutine BEGIN: called CC=1 SCAR=0.0
6 8 with 'Langertha::Manifest::Validation';
7  
8  
9 8 has id => ( is => 'ro', isa => 'Str', required => 1 );
10 8 has endpoint_ref => ( is => 'ro', isa => 'Str', required => 1 );
11 4 ▶has capabilities => ( is => 'ro', isa => 'HashRef', default => sub { {} } );
Subroutine __ANON__: called CC=1 SCAR=0.0
12  
13  
14 119 ▶around BUILDARGS => sub {
Subroutine __ANON__: called CC=5 SCAR=16.1
15 119 my ( $orig, $class, @args ) = @_;
16 119 my $args = $class->$orig(@args);
17 119 ▶ if ( exists $args->{capabilities} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $$args{"capabilities"}) 115 4 119
18 115 my $caps = $args->{capabilities};
19 115 ▶ $class->_error('capabilities: must be a JSON object') unless ref $caps eq 'HASH';
Branch: 1 branch
BranchTrueFalseTotal
unless ref $caps eq "HASH" 1 114 115
20 114 my %norm;
21 114 for my $name ( sort keys %$caps ) {
22 702 ▶ $class->_error( "capabilities: invalid capability name '" . $class->_display($name) . q{'} )
Branch: 1 branch
BranchTrueFalseTotal
unless $name =~ /\A[a-z][a-z0-9_]{0,63}\z/ 1 701 702
23 unless $name =~ /\A[a-z][a-z0-9_]{0,63}\z/;
24 701 $norm{$name} = $class->_bool( "capabilities: '$name'", $caps->{$name} );
25 }
26 107 $args->{capabilities} = \%norm;
27 }
28 111 return $args;
29 8 };
30  
31 111 ▶sub BUILD {
Subroutine BUILD: called CC=4 SCAR=14.3
Pod undocumented
32 111 my ($self) = @_;
33 111 my $id = $self->id;
34 # Control, format (bidi overrides such as U+202E), surrogate, private-use,
35 # unassigned and line/paragraph-separator characters are rejected: a client
36 # prints model ids.
37 111 ▶ $self->_error('id must be a non-empty model id without control or format characters (max 256)')
Branch: 1 branch
BranchTrueFalseTotal
unless length $id and length $id <= 256 and not $id =~ /[\p{C}\p{Zl}\p{Zp}]/ 3 108 111
Condition50%3/6
length $id and length $id <= 256 and not $id =~ /[\p{C}\p{Zl}\p{Zp}]/
!ll&&!rl&&r
03108
length $id and length $id <= 256
!ll&&!rl&&r
00111
MC/DC33%1/3
length $id and length $id <= 256 and not $id =~ /[\p{C}\p{Zl}\p{Zp}]/
length $id length $id <= 256 not $id =~ /[\p{C}\p{Zl}\p{Zp}]/
Truth table50%2/4
A and B and not(C)
A= length $idB= length $id <= 256C= not $id =~ /[\p{C}\p{Zl}\p{Zp}]/
ABCresult
0XX0
10X0
1100
1111
38 unless length $id && length $id <= 256 && $id !~ /[\p{C}\p{Zl}\p{Zp}]/;
39 108 $self->_check_id( 'endpoint_ref', $self->endpoint_ref );
40 108 return;
41 }
42  
43 42 ▶sub supports {
Subroutine supports: called CC=2 SCAR=6.9
Pod documented
44 42 my ( $self, $cap ) = @_;
45 42 ▶ return $self->capabilities->{$cap} ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$self->capabilities->{$cap} ? : 14 28 42
46 }
47  
48  
49 77 ▶sub from_hash {
Subroutine from_hash: called CC=2 SCAR=6.9
Pod documented
50 77 my ( $class, $data ) = @_;
51 77 $class->_check_fields( $data,
52 required => [qw( id endpoint_ref )],
53 optional => [qw( capabilities )],
54 );
55 return $class->new(
56 id => $class->_string( 'id', $data->{id} ),
57 endpoint_ref => $class->_string( 'endpoint_ref', $data->{endpoint_ref} ),
58 73 ▶ ( exists $data->{capabilities} ? ( capabilities => $data->{capabilities} ) : () ),
Branch: 1 branch
BranchTrueFalseTotal
exists $$data{'capabilities'} ? : 70 3 73
59 );
60 }
61  
62  
63 58 ▶sub to_hash {
Subroutine to_hash: called CC=2 SCAR=6.9
Pod documented
64 58 my ($self) = @_;
65 58 my $caps = $self->capabilities;
66 return {
67 id => $self->id,
68 endpoint_ref => $self->endpoint_ref,
69 capabilities => {
70 58 ▶ map { $_ => ( $caps->{$_} ? JSON::MaybeXS::true() : JSON::MaybeXS::false() ) } keys %$caps
Branch: 1 branch
BranchTrueFalseTotal
$$caps{$_} ? : 183 18 201
71 },
72 };
73 }
74  
75  
76 0 ▶sub TO_JSON { shift->to_hash }
Subroutine TO_JSON: not called CC=1 SCAR=6.9
Pod undocumented
77  
78 8 __PACKAGE__->meta->make_immutable;
79  
80  
81 8 1;
82  
83 __END__
« blib/lib/Langertha/Engine/VLLMHook.pm ↑ Summary blib/lib/Langertha/Engine/Cerebras.pm »