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

filter: Statementstmt 100% 32 / 32 Branchbran n/a Conditioncond 100% 4 / 4 MC/DCmcdc 100% 2 / 2 Subroutinesub 100% 13 / 13 Podpod 0.0% 0 / 4 totaltotal 92.7% 51 / 55 CC 3 SCAR 3.4
CC
3
Cov
100%
register_tools
3.0
BEGIN
1.0
BEGIN
1.0
CRAP 1.4
« blib/lib/SignalWire/REST/Namespaces/Project.pm ↑ Summary blib/lib/SignalWire/SWML/Document.pm »
1 package SignalWire::Skills::Builtin::Joke;
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 ();
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('joke', __PACKAGE__);
10  
11 7 ▶has '+skill_name' => (default => sub { 'joke' });
Subroutine __ANON__: called CC=1 SCAR=0.0
12 7 ▶has '+skill_description' => (default => sub { 'Tell jokes using the API Ninjas joke API' });
Subroutine __ANON__: called CC=1 SCAR=0.0
13 7 ▶has '+supports_multiple_instances' => (default => sub { 0 });
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=3 SCAR=11.0
Pod undocumented
18 3 my ($self) = @_;
19 3 ▶ my $tool_name = $self->params->{tool_name} // 'get_joke';
Condition100%2/2
$self->params->{"tool_name"} // "get_joke"
l!l
12
MC/DC100%1/1
$self->params->{"tool_name"} // "get_joke"
$self->params->{"tool_name"}
Truth table100%2/2
A
A= $self->params->{"tool_name"}
Aresult
11
00
20  
21 # DataMap-style registration
22 $self->agent->register_swaig_function({
23 function => $tool_name,
24 description => 'Get a random joke from API Ninjas',
25 parameters => {
26 type => 'object',
27 properties => {
28 type => {
29 type => 'string',
30 description => 'Type of joke',
31 enum => ['jokes', 'dadjokes'],
32 },
33 },
34 required => ['type'],
35 },
36 data_map => {
37 webhooks => [{
38 method => 'GET',
39 url => 'https://api.api-ninjas.com/v1/${args.type}',
40 3 ▶ headers => { 'X-Api-Key' => $self->params->{api_key} // '' },
Condition100%2/2
$self->params->{"api_key"} // ""
l!l
12
MC/DC100%1/1
$self->params->{"api_key"} // ""
$self->params->{"api_key"}
Truth table100%2/2
A
A= $self->params->{"api_key"}
Aresult
11
00
41 output => {
42 response => 'Here\'s a joke: ${array[0].joke}',
43 },
44 }],
45 },
46 });
47 }
48  
49 1 ▶sub get_global_data {
Subroutine get_global_data: called CC=1 SCAR=0.0
Pod undocumented
50 1 return { joke_skill_enabled => JSON::true };
51 }
52  
53 1 ▶sub _get_prompt_sections {
Subroutine _get_prompt_sections: called CC=1 SCAR=0.0
54 return [{
55 1 title => 'Joke Telling',
56 body => 'You can tell jokes to lighten the mood.',
57 bullets => [
58 'Use the joke tool when the user asks for a joke',
59 'Choose between regular jokes and dad jokes',
60 ],
61 }];
62 }
63  
64 1 ▶sub get_parameter_schema {
Subroutine get_parameter_schema: called CC=1 SCAR=0.0
Pod undocumented
65 return {
66 1 %{ SignalWire::Skills::SkillBase->get_parameter_schema },
67 api_key => { type => 'string', required => 1, hidden => 1 },
68 tool_name => { type => 'string', default => 'get_joke' },
69 };
70 }
71  
72 4 1;
« blib/lib/SignalWire/REST/Namespaces/Project.pm ↑ Summary blib/lib/SignalWire/SWML/Document.pm »