blib/lib/SignalWire/Skills/Builtin/Math.pm

filter: Statementstmt 95.3% 41 / 43 Branchbran 75.0% 3 / 4 Conditioncond 40.0% 2 / 5 MC/DCmcdc 0.0% 0 / 3 Subroutinesub 92.8% 13 / 14 Podpod 0.0% 0 / 3 totaltotal 81.9% 59 / 72 CC 5 SCAR 7.9
CC
5
Cov
88%
__ANON__
5.1
get_parameter_schema
2.0
register_tools
1.0
CRAP 2.2
« blib/lib/SignalWire/REST/Namespaces/Fabric.pm ↑ Summary blib/lib/SignalWire/REST/Namespaces/Datasphere.pm »
1 package SignalWire::Skills::Builtin::Math;
2 4 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 4 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 4 ▶use Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 4 extends 'SignalWire::Skills::SkillBase';
6  
7 4 ▶use SignalWire::Skills::SkillRegistry;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 4 SignalWire::Skills::SkillRegistry->register_skill('math', __PACKAGE__);
9  
10 8 ▶has '+skill_name' => (default => sub { 'math' });
Subroutine __ANON__: called CC=1 SCAR=0.0
11 8 ▶has '+skill_description' => (default => sub { 'Perform basic mathematical calculations' });
Subroutine __ANON__: called CC=1 SCAR=0.0
12 8 ▶has '+supports_multiple_instances' => (default => sub { 0 });
Subroutine __ANON__: called CC=1 SCAR=0.0
13  
14 7 ▶sub setup { 1 }
Subroutine setup: called CC=1 SCAR=0.0
Pod undocumented
15  
16 6 ▶sub register_tools {
Subroutine register_tools: called CC=1 SCAR=0.0
Pod undocumented
17 6 my ($self) = @_;
18  
19 $self->define_tool(
20 name => 'calculate',
21 description => 'Perform a mathematical calculation with basic operations (+, -, *, /, %, **)',
22 parameters => {
23 type => 'object',
24 properties => {
25 expression => { type => 'string', description => 'Mathematical expression to evaluate' },
26 },
27 required => ['expression'],
28 },
29 2 ▶ handler => sub {
Subroutine __ANON__: called CC=5 SCAR=16.3
30 2 my ($args, $raw) = @_;
31 2 require SignalWire::SWAIG::FunctionResult;
32 2 ▶ my $expr = $args->{expression} // '';
Condition50%1/2
$args->{"expression"} // ""
l!l
20
MC/DC0%0/1
$args->{"expression"} // ""
$args->{"expression"}
Truth table50%1/2
A
A= $args->{"expression"}
Aresult
11
00
33  
34 # Safe evaluation: only allow numbers and basic operators
35 2 ▶ if ($expr =~ /^[\d\s\+\-\*\/\%\.\(\)\^]+$/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($expr =~ m[^[\d\s\+\-\*/\%\.\(\)\^]+$]) 1 1 2
36 1 $expr =~ s/\^/**/g; # Convert ^ to **
37 4 ▶ my $result = eval { no strict; no warnings; eval $expr };
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
38 1 ▶ if (defined $result && !$@) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $result and not $@) 1 0 1
Condition33%1/3
defined $result and not $@
!ll&&!rl&&r
001
MC/DC0%0/2
defined $result and not $@
defined $result not $@
Truth table33%1/3
A and not(B)
A= defined $resultB= not $@
ABresult
0X0
100
111
39 1 return SignalWire::SWAIG::FunctionResult->new(
40 response => "The result of $args->{expression} is $result"
41 );
42 }
43 }
44 1 return SignalWire::SWAIG::FunctionResult->new(
45 response => "Could not evaluate expression: $args->{expression}"
46 );
47 },
48 6 );
49 }
50  
51 3 ▶sub _get_prompt_sections {
Subroutine _get_prompt_sections: called CC=1 SCAR=0.0
52 return [{
53 3 title => 'Mathematical Calculations',
54 body => '',
55 bullets => [
56 'Use the calculate tool for math operations',
57 'Supports +, -, *, /, %, and ** (exponentiation)',
58 ],
59 }];
60 }
61  
62 0 ▶sub get_parameter_schema {
Subroutine get_parameter_schema: not called CC=1 SCAR=6.9
Pod undocumented
63 return {
64 0 %{ SignalWire::Skills::SkillBase->get_parameter_schema },
65 };
66 }
67  
68 4 1;
« blib/lib/SignalWire/REST/Namespaces/Fabric.pm ↑ Summary blib/lib/SignalWire/REST/Namespaces/Datasphere.pm »