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

filter: Statementstmt 85.1% 40 / 47 Branchbran 100% 4 / 4 Conditioncond 58.3% 7 / 12 MC/DCmcdc 33.3% 2 / 6 Subroutinesub 86.6% 13 / 15 Podpod 0.0% 0 / 4 totaltotal 75.0% 66 / 88 CC 9 SCAR 11.0
CC
9
Cov
81%
register_tools
6.3
__ANON__
6.0
get_global_data
3.2
CRAP 3.0
« blib/lib/SignalWire/REST/Namespaces/Video.pm ↑ Summary blib/lib/SignalWire/Skills/Builtin/CustomSkills.pm »
1 package SignalWire::Skills::Builtin::InfoGatherer;
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 ▶use JSON qw(encode_json);
Subroutine BEGIN: called CC=1 SCAR=0.0
6 4 extends 'SignalWire::Skills::SkillBase';
7  
8 4 ▶use SignalWire::Skills::SkillRegistry;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 4 SignalWire::Skills::SkillRegistry->register_skill('info_gatherer', __PACKAGE__);
10  
11 7 ▶has '+skill_name' => (default => sub { 'info_gatherer' });
Subroutine __ANON__: called CC=1 SCAR=0.0
12 7 ▶has '+skill_description' => (default => sub { 'Gather answers to a configurable list of questions' });
Subroutine __ANON__: called CC=1 SCAR=0.0
13 7 ▶has '+supports_multiple_instances' => (default => sub { 1 });
Subroutine __ANON__: called CC=1 SCAR=0.0
14  
15 4 ▶sub setup { 1 }
Subroutine setup: called CC=1 SCAR=0.0
Pod undocumented
16  
17 3 ▶sub register_tools {
Subroutine register_tools: called CC=5 SCAR=18.4
Pod undocumented
18 3 my ($self) = @_;
19 3 ▶ my $prefix = $self->params->{prefix} // '';
Condition100%2/2
$self->params->{"prefix"} // ""
l!l
12
MC/DC100%1/1
$self->params->{"prefix"} // ""
$self->params->{"prefix"}
Truth table100%2/2
A
A= $self->params->{"prefix"}
Aresult
11
00
20 3 ▶ my $questions = $self->params->{questions} // [];
Condition100%2/2
$self->params->{"questions"} // []
l!l
21
MC/DC100%1/1
$self->params->{"questions"} // []
$self->params->{"questions"}
Truth table100%2/2
A
A= $self->params->{"questions"}
Aresult
11
00
21  
22 3 ▶ my $start_name = $prefix ? "${prefix}_start_questions" : 'start_questions';
Branch: 1 branch
BranchTrueFalseTotal
$prefix ? : 1 2 3
23 3 ▶ my $submit_name = $prefix ? "${prefix}_submit_answer" : 'submit_answer';
Branch: 1 branch
BranchTrueFalseTotal
$prefix ? : 1 2 3
24  
25 $self->define_tool(
26 name => $start_name,
27 description => 'Start the question-gathering process and return the first question',
28 parameters => { type => 'object', properties => {} },
29 0 ▶ handler => sub {
Subroutine __ANON__: not called CC=2 SCAR=17.9
30 0 my ($args, $raw) = @_;
31 0 require SignalWire::SWAIG::FunctionResult;
32 0 ▶ my $first = $questions->[0]{question_text} // 'No questions configured';
Condition0%0/2
$questions->[0]{"question_text"} // "No questions configured"
l!l
00
MC/DC0%0/1
$questions->[0]{"question_text"} // "No questions configured"
$questions->[0]{"question_text"}
Truth table0%0/2
A
A= $questions->[0]{"question_text"}
Aresult
11
00
33 0 return SignalWire::SWAIG::FunctionResult->new(
34 response => $first,
35 );
36 },
37 3 );
38  
39 $self->define_tool(
40 name => $submit_name,
41 description => 'Submit an answer to the current question',
42 parameters => {
43 type => 'object',
44 properties => {
45 answer => { type => 'string', description => 'The answer' },
46 confirmed_by_user => { type => 'boolean', description => 'Whether user confirmed' },
47 },
48 required => ['answer'],
49 },
50 0 ▶ handler => sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
51 0 my ($args, $raw) = @_;
52 0 require SignalWire::SWAIG::FunctionResult;
53 0 return SignalWire::SWAIG::FunctionResult->new(
54 response => "Answer recorded: $args->{answer}",
55 );
56 },
57 3 );
58 }
59  
60 1 ▶sub get_global_data {
Subroutine get_global_data: called CC=3 SCAR=11.7
Pod undocumented
61 1 my ($self) = @_;
62 1 ▶ my $ns = $self->params->{prefix} // 'info_gatherer';
Condition50%1/2
$self->params->{"prefix"} // "info_gatherer"
l!l
01
MC/DC0%0/1
$self->params->{"prefix"} // "info_gatherer"
$self->params->{"prefix"}
Truth table50%1/2
A
A= $self->params->{"prefix"}
Aresult
11
00
63 return {
64 $ns => {
65 1 ▶ questions => $self->params->{questions} // [],
Condition50%1/2
$self->params->{"questions"} // []
l!l
10
MC/DC0%0/1
$self->params->{"questions"} // []
$self->params->{"questions"}
Truth table50%1/2
A
A= $self->params->{"questions"}
Aresult
11
00
66 question_index => 0,
67 answers => [],
68 },
69 };
70 }
71  
72 1 ▶sub _get_prompt_sections {
Subroutine _get_prompt_sections: called CC=2 SCAR=7.1
73 1 my ($self) = @_;
74 1 ▶ my $key = $self->params->{prefix} // 'info_gatherer';
Condition50%1/2
$self->params->{"prefix"} // "info_gatherer"
l!l
01
MC/DC0%0/1
$self->params->{"prefix"} // "info_gatherer"
$self->params->{"prefix"}
Truth table50%1/2
A
A= $self->params->{"prefix"}
Aresult
11
00
75 return [{
76 1 title => "Info Gatherer ($key)",
77 body => 'Ask the user a series of questions and collect their answers.',
78 bullets => [
79 'Ask questions one at a time',
80 'Wait for the user to answer before proceeding',
81 'Confirm answers when required',
82 ],
83 }];
84 }
85  
86 1 ▶sub get_parameter_schema {
Subroutine get_parameter_schema: called CC=1 SCAR=0.0
Pod undocumented
87 return {
88 1 %{ SignalWire::Skills::SkillBase->get_parameter_schema },
89 questions => { type => 'array', required => 1, description => 'List of question objects' },
90 prefix => { type => 'string', description => 'Prefix for tool names' },
91 completion_message => { type => 'string', description => 'Message after all questions answered' },
92 };
93 }
94  
95 4 1;
« blib/lib/SignalWire/REST/Namespaces/Video.pm ↑ Summary blib/lib/SignalWire/Skills/Builtin/CustomSkills.pm »