blib/lib/Langertha/Input/Tools.pm

filter: Statementstmt 100% 52 / 52 Branchbran 50.0% 7 / 14 Conditioncond 50.0% 14 / 28 MC/DCmcdc 0.0% 0 / 14 Subroutinesub 100% 12 / 12 Podpod 0.0% 0 / 6 totaltotal 67.4% 85 / 126 CC 22 SCAR 17.2
CC
22
Cov
78%
to_openai_tools
8.1
to_anthropic_tools
8.1
to_openai_tool_choice
6.1
CRAP 5.6
« blib/lib/Langertha/Metrics.pm ↑ Summary blib/lib/Langertha/Role/ParallelToolUse.pm »
1 package Langertha::Input::Tools;
2 4 our $VERSION = '0.505';
3 # ABSTRACT: Backwards-compat facade over Langertha::Tool / Langertha::ToolChoice
4 4 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 4 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 4 ▶use Carp ();
Subroutine BEGIN: called CC=1 SCAR=0.0
7 4 ▶use Scalar::Util qw( blessed );
Subroutine BEGIN: called CC=1 SCAR=0.0
8 4 ▶use Langertha::Tool;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 4 ▶use Langertha::ToolChoice;
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 4 Carp::carp(
12 "Langertha::Input::Tools is a backwards-compatibility facade. New code should use "
13 . "Langertha::Tool / Langertha::ToolChoice directly."
14 );
15  
16 # All methods here are kept for backwards compatibility with Skeid/Knarr
17 # and other existing consumers. New code should use Langertha::Tool and
18 # Langertha::ToolChoice directly.
19  
20 2 ▶sub normalize_tools {
Subroutine normalize_tools: called CC=1 SCAR=0.0
Pod undocumented
21 2 my ($class, $tools) = @_;
22 2 return [ map { $_->to_hash } @{ Langertha::Tool->from_list($tools) } ];
23 }
24  
25 2 ▶sub to_openai_tools {
Subroutine to_openai_tools: called CC=7 SCAR=20.9
Pod undocumented
26 2 my ($class, $canonical_tools) = @_;
27 2 my @out;
28 2 ▶ for my $hash ( @{ $canonical_tools || [] } ) {
Condition50%1/2
$canonical_tools || []
l!l
20
MC/DC0%0/1
$canonical_tools || []
$canonical_tools
Truth table50%1/2
A
A= $canonical_tools
Aresult
11
00
29 4 ▶ next unless ref($hash) eq 'HASH';
Branch: 1 branch
BranchTrueFalseTotal
unless ref $hash eq "HASH" 0 4 4
30 4 ▶ my $name = $hash->{name} // 'tool';
Condition50%1/2
$$hash{"name"} // "tool"
l!l
40
MC/DC0%0/1
$$hash{"name"} // "tool"
$$hash{"name"}
Truth table50%1/2
A
A= $$hash{"name"}
Aresult
11
00
31 push @out, Langertha::Tool->new(
32 name => $name,
33 description => ( $hash->{description} // '' ),
34 4 ▶ input_schema => ( $hash->{input_schema} || { type => 'object', properties => {} } ),
Condition50%2/4
$$hash{"description"} // ""
l!l
40
$$hash{'input_schema'} || {'type', 'object', 'properties', {}}
l!l
40
MC/DC0%0/1
$$hash{"description"} // ""
$$hash{"description"}
MC/DC0%0/1
$$hash{'input_schema'} || {'type', 'object', 'properties', {}}
$$hash{'input_schema'}
Truth table50%1/2
A
A= $$hash{"description"}
Aresult
11
00
Truth table50%1/2
A
A= $$hash{'input_schema'}
Aresult
11
00
35 )->to_openai;
36 }
37 2 return \@out;
38 }
39  
40 2 ▶sub to_anthropic_tools {
Subroutine to_anthropic_tools: called CC=7 SCAR=20.9
Pod undocumented
41 2 my ($class, $canonical_tools) = @_;
42 2 my @out;
43 2 ▶ for my $hash ( @{ $canonical_tools || [] } ) {
Condition50%1/2
$canonical_tools || []
l!l
20
MC/DC0%0/1
$canonical_tools || []
$canonical_tools
Truth table50%1/2
A
A= $canonical_tools
Aresult
11
00
44 4 ▶ next unless ref($hash) eq 'HASH';
Branch: 1 branch
BranchTrueFalseTotal
unless ref $hash eq "HASH" 0 4 4
45 4 ▶ my $name = $hash->{name} // 'tool';
Condition50%1/2
$$hash{"name"} // "tool"
l!l
40
MC/DC0%0/1
$$hash{"name"} // "tool"
$$hash{"name"}
Truth table50%1/2
A
A= $$hash{"name"}
Aresult
11
00
46 push @out, Langertha::Tool->new(
47 name => $name,
48 description => ( $hash->{description} // '' ),
49 4 ▶ input_schema => ( $hash->{input_schema} || { type => 'object', properties => {} } ),
Condition50%2/4
$$hash{"description"} // ""
l!l
40
$$hash{'input_schema'} || {'type', 'object', 'properties', {}}
l!l
40
MC/DC0%0/1
$$hash{"description"} // ""
$$hash{"description"}
MC/DC0%0/1
$$hash{'input_schema'} || {'type', 'object', 'properties', {}}
$$hash{'input_schema'}
Truth table50%1/2
A
A= $$hash{"description"}
Aresult
11
00
Truth table50%1/2
A
A= $$hash{'input_schema'}
Aresult
11
00
50 )->to_anthropic;
51 }
52 2 return \@out;
53 }
54  
55 3 ▶sub normalize_tool_choice {
Subroutine normalize_tool_choice: called CC=2 SCAR=7.1
Pod undocumented
56 3 my ($class, $tool_choice) = @_;
57 3 my $tc = Langertha::ToolChoice->from_hash($tool_choice);
58 3 ▶ return $tc ? $tc->to_hash : undef;
Branch: 1 branch
BranchTrueFalseTotal
$tc ? : 3 0 3
59 }
60  
61 2 ▶sub to_openai_tool_choice {
Subroutine to_openai_tool_choice: called CC=5 SCAR=18.1
Pod undocumented
62 2 my ($class, $canonical_tool_choice) = @_;
63 2 ▶ return undef unless ref($canonical_tool_choice) eq 'HASH'
Branch: 1 branch
BranchTrueFalseTotal
unless ref $canonical_tool_choice eq "HASH" or builtin::blessed($canonical_tool_choice) and $canonical_tool_choice->isa("Langertha::ToolChoice") 0 2 2
Condition50%3/6
ref $canonical_tool_choice eq "HASH" or builtin::blessed($canonical_tool_choice) and $canonical_tool_choice->isa("Langertha::ToolChoice")
l!l&&r!l&&!r
110
builtin::blessed($canonical_tool_choice) and $canonical_tool_choice->isa("Langertha::ToolChoice")
!ll&&!rl&&r
001
MC/DC0%0/3
ref $canonical_tool_choice eq "HASH" or builtin::blessed($canonical_tool_choice) and $canonical_tool_choice->isa("Langertha::ToolChoice")
ref $canonical_tool_choice eq "HASH" builtin::blessed($canonical_tool_choice) $canonical_tool_choice->isa("Langertha::ToolChoice")
Truth table50%2/4
A or B and C
A= ref $canonical_tool_choice eq "HASH"B= builtin::blessed($canonical_tool_choice)C= $canonical_tool_choice->isa("Langertha::ToolChoice")
ABCresult
1XX1
0111
00X0
0100
64 || ( blessed($canonical_tool_choice) && $canonical_tool_choice->isa('Langertha::ToolChoice') );
65 2 my $tc = Langertha::ToolChoice->from_hash($canonical_tool_choice);
66 2 ▶ return $tc ? $tc->to_openai : undef;
Branch: 1 branch
BranchTrueFalseTotal
$tc ? : 2 0 2
67 }
68  
69 2 ▶sub to_anthropic_tool_choice {
Subroutine to_anthropic_tool_choice: called CC=5 SCAR=18.1
Pod undocumented
70 2 my ($class, $canonical_tool_choice) = @_;
71 2 ▶ return undef unless ref($canonical_tool_choice) eq 'HASH'
Branch: 1 branch
BranchTrueFalseTotal
unless ref $canonical_tool_choice eq "HASH" or builtin::blessed($canonical_tool_choice) and $canonical_tool_choice->isa("Langertha::ToolChoice") 0 2 2
Condition50%3/6
ref $canonical_tool_choice eq "HASH" or builtin::blessed($canonical_tool_choice) and $canonical_tool_choice->isa("Langertha::ToolChoice")
l!l&&r!l&&!r
110
builtin::blessed($canonical_tool_choice) and $canonical_tool_choice->isa("Langertha::ToolChoice")
!ll&&!rl&&r
001
MC/DC0%0/3
ref $canonical_tool_choice eq "HASH" or builtin::blessed($canonical_tool_choice) and $canonical_tool_choice->isa("Langertha::ToolChoice")
ref $canonical_tool_choice eq "HASH" builtin::blessed($canonical_tool_choice) $canonical_tool_choice->isa("Langertha::ToolChoice")
Truth table50%2/4
A or B and C
A= ref $canonical_tool_choice eq "HASH"B= builtin::blessed($canonical_tool_choice)C= $canonical_tool_choice->isa("Langertha::ToolChoice")
ABCresult
1XX1
0111
00X0
0100
72 || ( blessed($canonical_tool_choice) && $canonical_tool_choice->isa('Langertha::ToolChoice') );
73 2 my $tc = Langertha::ToolChoice->from_hash($canonical_tool_choice);
74 2 ▶ return $tc ? $tc->to_anthropic : undef;
Branch: 1 branch
BranchTrueFalseTotal
$tc ? : 2 0 2
75 }
76  
77 4 1;
78  
79 __END__
« blib/lib/Langertha/Metrics.pm ↑ Summary blib/lib/Langertha/Role/ParallelToolUse.pm »