blib/lib/SignalWire/SWAIG/FunctionResult.pm

filter: Statementstmt 69.6% 200 / 287 Branchbran 39.6% 50 / 126 Conditioncond 22.6% 29 / 128 MC/DCmcdc 4.4% 3 / 67 Subroutinesub 86.2% 50 / 58 Podpod 0.0% 0 / 50 totaltotal 46.3% 332 / 716 CC 119 SCAR 46.3
CC
119
Cov
52%
pay
552.0
record_call
132.0
tap
132.0
CRAP 102.1
« blib/lib/SignalWire/Relay/Client.pm ↑ Summary blib/lib/SignalWire/Server/AgentServer.pm »
1 package SignalWire::SWAIG::FunctionResult;
2 16 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 16 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 16 ▶use Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 16 ▶use JSON ();
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 has 'response' => (
8 is => 'rw',
9 2 ▶ default => sub { '' },
Subroutine __ANON__: called CC=1 SCAR=0.0
10 16 );
11  
12 has 'action' => (
13 is => 'rw',
14 89 ▶ default => sub { [] },
Subroutine __ANON__: called CC=1 SCAR=0.0
15 16 );
16  
17 has 'post_process' => (
18 is => 'rw',
19 88 ▶ default => sub { 0 },
Subroutine __ANON__: called CC=1 SCAR=0.0
20 16 );
21  
22 # Constructor: new(response => "text") or new("text") or new("text", post_process => 1)
23 89 ▶around BUILDARGS => sub {
Subroutine __ANON__: called CC=6 SCAR=19.4
24 89 my ($orig, $class, @args) = @_;
25 89 ▶ if (@args == 1 && !ref $args[0]) {
Branch: 1 branch
BranchTrueFalseTotal
if (@args == 1 and not ref $args[0]) 59 30 89
Condition66%2/3
@args == 1 and not ref $args[0]
!ll&&!rl&&r
30059
MC/DC50%1/2
@args == 1 and not ref $args[0]
@args == 1 not ref $args[0]
Truth table66%2/3
A and not(B)
A= @args == 1B= not ref $args[0]
ABresult
0X0
100
111
26 59 return $class->$orig(response => $args[0]);
27 }
28 30 ▶ if (@args >= 1 && !ref $args[0] && $args[0] !~ /^(response|action|post_process)$/) {
Branch: 1 branch
BranchTrueFalseTotal
if (@args >= 1 and not ref $args[0] and not $args[0] =~ /^(response|action|post_process)$/) 0 30 30
Condition66%4/6
@args >= 1 and not ref $args[0] and not $args[0] =~ /^(response|action|post_process)$/
!ll&&!rl&&r
2280
@args >= 1 and not ref $args[0]
!ll&&!rl&&r
2028
MC/DC0%0/3
@args >= 1 and not ref $args[0] and not $args[0] =~ /^(response|action|post_process)$/
@args >= 1 not ref $args[0] not $args[0] =~ /^(response|action|post_process)$/
Truth table50%2/4
A and not(B) and not(C)
A= @args >= 1B= not ref $args[0]C= not $args[0] =~ /^(response|action|post_process)$/
ABCresult
0XX0
10X0
1100
1111
29 0 my $resp = shift @args;
30 0 return $class->$orig(response => $resp, @args);
31 }
32 30 return $class->$orig(@args);
33 16 };
34  
35 # --- Core methods ---
36  
37 1 ▶sub set_response {
Subroutine set_response: called CC=1 SCAR=0.0
Pod undocumented
38 1 my ($self, $response) = @_;
39 1 $self->response($response);
40 1 return $self;
41 }
42  
43 3 ▶sub set_post_process {
Subroutine set_post_process: called CC=2 SCAR=7.1
Pod undocumented
44 3 my ($self, $post_process) = @_;
45 3 ▶ $self->post_process($post_process ? 1 : 0);
Branch: 1 branch
BranchTrueFalseTotal
$post_process ? : 3 0 3
46 3 return $self;
47 }
48  
49 44 ▶sub add_action {
Subroutine add_action: called CC=1 SCAR=0.0
Pod undocumented
50 44 my ($self, $name, $data) = @_;
51 44 push @{ $self->action }, { $name => $data };
52 44 return $self;
53 }
54  
55 1 ▶sub add_actions {
Subroutine add_actions: called CC=1 SCAR=0.0
Pod undocumented
56 1 my ($self, $actions) = @_;
57 1 push @{ $self->action }, @$actions;
58 1 return $self;
59 }
60  
61 # --- Call Control ---
62  
63 2 ▶sub connect {
Subroutine connect: called CC=4 SCAR=13.9
Pod undocumented
64 2 my ($self, $destination, %opts) = @_;
65 2 ▶ my $final = exists $opts{final} ? $opts{final} : 1;
Branch: 1 branch
BranchTrueFalseTotal
exists $opts{'final'} ? : 2 0 2
66 2 my $from = $opts{from};
67  
68 2 my $connect_params = { to => $destination };
69 2 ▶ $connect_params->{from} = $from if defined $from;
Branch: 1 branch
BranchTrueFalseTotal
if defined $from 1 1 2
70  
71 2 ▶ my $swml_action = {
Branch: 1 branch
BranchTrueFalseTotal
$final ? : 1 1 2
72 SWML => {
73 sections => {
74 main => [{ connect => $connect_params }],
75 },
76 version => '1.0.0',
77 },
78 transfer => $final ? 'true' : 'false',
79 };
80  
81 2 push @{ $self->action }, $swml_action;
82 2 return $self;
83 }
84  
85 1 ▶sub swml_transfer {
Subroutine swml_transfer: called CC=3 SCAR=11.2
Pod undocumented
86 1 my ($self, $dest, $ai_response, %opts) = @_;
87 1 ▶ my $final = exists $opts{final} ? $opts{final} : 1;
Branch: 1 branch
BranchTrueFalseTotal
exists $opts{'final'} ? : 0 1 1
88  
89 1 ▶ my $swml_action = {
Branch: 1 branch
BranchTrueFalseTotal
$final ? : 1 0 1
90 SWML => {
91 version => '1.0.0',
92 sections => {
93 main => [
94 { set => { ai_response => $ai_response } },
95 { transfer => { dest => $dest } },
96 ],
97 },
98 },
99 transfer => $final ? 'true' : 'false',
100 };
101  
102 1 push @{ $self->action }, $swml_action;
103 1 return $self;
104 }
105  
106 1 ▶sub hangup {
Subroutine hangup: called CC=1 SCAR=0.0
Pod undocumented
107 1 my ($self) = @_;
108 1 return $self->add_action('hangup', JSON::true);
109 }
110  
111 4 ▶sub hold {
Subroutine hold: called CC=4 SCAR=13.9
Pod undocumented
112 4 my ($self, $timeout) = @_;
113 4 ▶ $timeout //= 300;
Condition50%1/2
$timeout //= 300
l!l
40
MC/DC0%0/1
$timeout //= 300
$timeout
Truth table50%1/2
A
A= $timeout
Aresult
11
00
114 4 ▶ $timeout = 0 if $timeout < 0;
Branch: 1 branch
BranchTrueFalseTotal
if $timeout < 0 1 3 4
115 4 ▶ $timeout = 900 if $timeout > 900;
Branch: 1 branch
BranchTrueFalseTotal
if $timeout > 900 1 3 4
116 4 return $self->add_action('hold', $timeout);
117 }
118  
119 3 ▶sub wait_for_user {
Subroutine wait_for_user: called CC=5 SCAR=16.6
Pod undocumented
120 3 my ($self, %opts) = @_;
121 3 my $enabled = $opts{enabled};
122 3 my $timeout = $opts{timeout};
123 3 my $answer_first = $opts{answer_first};
124  
125 3 my $value;
126 3 ▶ if ($answer_first) {
Branch: 3 branches
BranchTrueFalseTotal
if ($answer_first) { } 1 2 3
elsif (defined $timeout) { } 1 1 2
elsif (defined $enabled) { } 0 1 1
127 1 $value = 'answer_first';
128 } elsif (defined $timeout) {
129 1 $value = $timeout;
130 } elsif (defined $enabled) {
131 0 ▶ $value = $enabled ? JSON::true : JSON::false;
Branch: 1 branch
BranchTrueFalseTotal
$enabled ? : 0 0 0
132 } else {
133 1 $value = JSON::true;
134 }
135 3 return $self->add_action('wait_for_user', $value);
136 }
137  
138 1 ▶sub stop {
Subroutine stop: called CC=1 SCAR=0.0
Pod undocumented
139 1 my ($self) = @_;
140 1 return $self->add_action('stop', JSON::true);
141 }
142  
143 # --- State & Data ---
144  
145 2 ▶sub update_global_data {
Subroutine update_global_data: called CC=1 SCAR=0.0
Pod undocumented
146 2 my ($self, $data) = @_;
147 2 return $self->add_action('set_global_data', $data);
148 }
149  
150 1 ▶sub remove_global_data {
Subroutine remove_global_data: called CC=1 SCAR=0.0
Pod undocumented
151 1 my ($self, $keys) = @_;
152 1 return $self->add_action('unset_global_data', $keys);
153 }
154  
155 1 ▶sub set_metadata {
Subroutine set_metadata: called CC=1 SCAR=0.0
Pod undocumented
156 1 my ($self, $data) = @_;
157 1 return $self->add_action('set_meta_data', $data);
158 }
159  
160 1 ▶sub remove_metadata {
Subroutine remove_metadata: called CC=1 SCAR=0.0
Pod undocumented
161 1 my ($self, $keys) = @_;
162 1 return $self->add_action('unset_meta_data', $keys);
163 }
164  
165 1 ▶sub swml_user_event {
Subroutine swml_user_event: called CC=1 SCAR=0.0
Pod undocumented
166 1 my ($self, $event_data) = @_;
167 1 my $swml_action = {
168 sections => {
169 main => [{
170 user_event => { event => $event_data },
171 }],
172 },
173 version => '1.0.0',
174 };
175 1 return $self->add_action('SWML', $swml_action);
176 }
177  
178 1 ▶sub swml_change_step {
Subroutine swml_change_step: called CC=1 SCAR=0.0
Pod undocumented
179 1 my ($self, $step_name) = @_;
180 1 return $self->add_action('change_step', $step_name);
181 }
182  
183 1 ▶sub swml_change_context {
Subroutine swml_change_context: called CC=1 SCAR=0.0
Pod undocumented
184 1 my ($self, $context_name) = @_;
185 1 return $self->add_action('change_context', $context_name);
186 }
187  
188 2 ▶sub switch_context {
Subroutine switch_context: called CC=9 SCAR=22.9
Pod undocumented
189 2 my ($self, %opts) = @_;
190 2 my $system_prompt = $opts{system_prompt};
191 2 my $user_prompt = $opts{user_prompt};
192 2 my $consolidate = $opts{consolidate};
193 2 my $full_reset = $opts{full_reset};
194  
195 2 ▶ if ($system_prompt && !$user_prompt && !$consolidate && !$full_reset) {
Branch: 1 branch
BranchTrueFalseTotal
if ($system_prompt and not $user_prompt and not $consolidate and not $full_reset) 1 1 2
Condition66%6/9
$system_prompt and not $user_prompt and not $consolidate and not $full_reset
!ll&&!rl&&r
101
$system_prompt and not $user_prompt and not $consolidate
!ll&&!rl&&r
101
$system_prompt and not $user_prompt
!ll&&!rl&&r
011
MC/DC25%1/4
$system_prompt and not $user_prompt and not $consolidate and not $full_reset
$system_prompt not $user_prompt not $consolidate not $full_reset
Truth table40%2/5
A and not(B) and not(C) and not(D)
A= $system_promptB= not $user_promptC= not $consolidateD= not $full_reset
ABCDresult
0XXX0
10XX0
110X0
11100
11111
196 1 return $self->add_action('context_switch', $system_prompt);
197 }
198  
199 1 my %ctx;
200 1 ▶ $ctx{system_prompt} = $system_prompt if $system_prompt;
Branch: 1 branch
BranchTrueFalseTotal
if $system_prompt 1 0 1
201 1 ▶ $ctx{user_prompt} = $user_prompt if $user_prompt;
Branch: 1 branch
BranchTrueFalseTotal
if $user_prompt 1 0 1
202 1 ▶ $ctx{consolidate} = JSON::true if $consolidate;
Branch: 1 branch
BranchTrueFalseTotal
if $consolidate 1 0 1
203 1 ▶ $ctx{full_reset} = JSON::true if $full_reset;
Branch: 1 branch
BranchTrueFalseTotal
if $full_reset 1 0 1
204 1 return $self->add_action('context_switch', \%ctx);
205 }
206  
207 1 ▶sub replace_in_history {
Subroutine replace_in_history: called CC=2 SCAR=7.6
Pod undocumented
208 1 my ($self, $text) = @_;
209 1 ▶ $text //= JSON::true;
Condition33%1/3
$text //= JSON::true()
l!l&&r!l&&!r
100
MC/DC0%0/2
$text //= JSON::true()
$text JSON::true()
Truth table33%1/3
A //= B
A= $textB= JSON::true()
ABresult
1X1
011
000
210 1 return $self->add_action('replace_in_history', $text);
211 }
212  
213 # --- Media ---
214  
215 2 ▶sub say {
Subroutine say: called CC=1 SCAR=0.0
Pod undocumented
216 2 my ($self, $text) = @_;
217 2 return $self->add_action('say', $text);
218 }
219  
220 2 ▶sub play_background_file {
Subroutine play_background_file: called CC=2 SCAR=6.9
Pod undocumented
221 2 my ($self, $filename, %opts) = @_;
222 2 my $wait = $opts{wait};
223 2 ▶ if ($wait) {
Branch: 1 branch
BranchTrueFalseTotal
if ($wait) 1 1 2
224 1 return $self->add_action('playback_bg', { file => $filename, wait => JSON::true });
225 }
226 1 return $self->add_action('playback_bg', $filename);
227 }
228  
229 1 ▶sub stop_background_file {
Subroutine stop_background_file: called CC=1 SCAR=0.0
Pod undocumented
230 1 my ($self) = @_;
231 1 return $self->add_action('stop_playback_bg', JSON::true);
232 }
233  
234 0 ▶sub record_call {
Subroutine record_call: not called CC=11 SCAR=48.8
Pod undocumented
235 0 my ($self, %opts) = @_;
236 0 my $control_id = $opts{control_id};
237 0 ▶ my $stereo = $opts{stereo} // 0;
Condition0%0/2
$opts{"stereo"} // 0
l!l
00
MC/DC0%0/1
$opts{"stereo"} // 0
$opts{"stereo"}
Truth table0%0/2
A
A= $opts{"stereo"}
Aresult
11
00
238 0 ▶ my $format = $opts{format} // 'wav';
Condition0%0/2
$opts{"format"} // "wav"
l!l
00
MC/DC0%0/1
$opts{"format"} // "wav"
$opts{"format"}
Truth table0%0/2
A
A= $opts{"format"}
Aresult
11
00
239 0 ▶ my $direction = $opts{direction} // 'both';
Condition0%0/2
$opts{"direction"} // "both"
l!l
00
MC/DC0%0/1
$opts{"direction"} // "both"
$opts{"direction"}
Truth table0%0/2
A
A= $opts{"direction"}
Aresult
11
00
240  
241 0 ▶ die "format must be 'wav' or 'mp3'" unless $format eq 'wav' || $format eq 'mp3';
Branch: 1 branch
BranchTrueFalseTotal
unless $format eq "wav" or $format eq "mp3" 0 0 0
Condition0%0/3
$format eq "wav" or $format eq "mp3"
l!l&&r!l&&!r
000
MC/DC0%0/2
$format eq "wav" or $format eq "mp3"
$format eq "wav" $format eq "mp3"
Truth table0%0/3
A or B
A= $format eq "wav"B= $format eq "mp3"
ABresult
1X1
011
000
242 0 ▶ die "direction must be 'speak', 'listen', or 'both'"
Branch: 1 branch
BranchTrueFalseTotal
unless $direction eq "speak" or $direction eq "listen" or $direction eq "both" 0 0 0
Condition0%0/6
$direction eq "speak" or $direction eq "listen" or $direction eq "both"
l!l&&r!l&&!r
000
$direction eq "speak" or $direction eq "listen"
l!l&&r!l&&!r
000
MC/DC0%0/3
$direction eq "speak" or $direction eq "listen" or $direction eq "both"
$direction eq "speak" $direction eq "listen" $direction eq "both"
Truth table0%0/4
A or B or C
A= $direction eq "speak"B= $direction eq "listen"C= $direction eq "both"
ABCresult
1XX1
01X1
0011
0000
243 unless $direction eq 'speak' || $direction eq 'listen' || $direction eq 'both';
244  
245 0 ▶ my %params = (
Branch: 1 branch
BranchTrueFalseTotal
$stereo ? : 0 0 0
246 stereo => $stereo ? JSON::true : JSON::false,
247 format => $format,
248 direction => $direction,
249 );
250 0 ▶ $params{control_id} = $control_id if $control_id;
Branch: 1 branch
BranchTrueFalseTotal
if $control_id 0 0 0
251  
252 0 my $swml_doc = {
253 version => '1.0.0',
254 sections => { main => [{ record_call => \%params }] },
255 };
256 0 return $self->execute_swml($swml_doc);
257 }
258  
259 0 ▶sub stop_record_call {
Subroutine stop_record_call: not called CC=2 SCAR=17.9
Pod undocumented
260 0 my ($self, %opts) = @_;
261 0 my $control_id = $opts{control_id};
262 0 my %params;
263 0 ▶ $params{control_id} = $control_id if $control_id;
Branch: 1 branch
BranchTrueFalseTotal
if $control_id 0 0 0
264  
265 0 my $swml_doc = {
266 version => '1.0.0',
267 sections => { main => [{ stop_record_call => \%params }] },
268 };
269 0 return $self->execute_swml($swml_doc);
270 }
271  
272 # --- Speech & AI ---
273  
274 1 ▶sub add_dynamic_hints {
Subroutine add_dynamic_hints: called CC=1 SCAR=0.0
Pod undocumented
275 1 my ($self, $hints) = @_;
276 1 return $self->add_action('add_dynamic_hints', $hints);
277 }
278  
279 1 ▶sub clear_dynamic_hints {
Subroutine clear_dynamic_hints: called CC=1 SCAR=0.0
Pod undocumented
280 1 my ($self) = @_;
281 1 push @{ $self->action }, { clear_dynamic_hints => {} };
282 1 return $self;
283 }
284  
285 1 ▶sub set_end_of_speech_timeout {
Subroutine set_end_of_speech_timeout: called CC=1 SCAR=0.0
Pod undocumented
286 1 my ($self, $ms) = @_;
287 1 return $self->add_action('end_of_speech_timeout', $ms);
288 }
289  
290 1 ▶sub set_speech_event_timeout {
Subroutine set_speech_event_timeout: called CC=1 SCAR=0.0
Pod undocumented
291 1 my ($self, $ms) = @_;
292 1 return $self->add_action('speech_event_timeout', $ms);
293 }
294  
295 1 ▶sub toggle_functions {
Subroutine toggle_functions: called CC=1 SCAR=0.0
Pod undocumented
296 1 my ($self, $toggles) = @_;
297 1 return $self->add_action('toggle_functions', $toggles);
298 }
299  
300 1 ▶sub enable_functions_on_timeout {
Subroutine enable_functions_on_timeout: called CC=3 SCAR=11.7
Pod undocumented
301 1 my ($self, $enabled) = @_;
302 1 ▶ $enabled //= 1;
Condition50%1/2
$enabled //= 1
l!l
10
MC/DC0%0/1
$enabled //= 1
$enabled
Truth table50%1/2
A
A= $enabled
Aresult
11
00
303 1 ▶ return $self->add_action('functions_on_speaker_timeout', $enabled ? JSON::true : JSON::false);
Branch: 1 branch
BranchTrueFalseTotal
$enabled ? : 1 0 1
304 }
305  
306 1 ▶sub enable_extensive_data {
Subroutine enable_extensive_data: called CC=3 SCAR=11.7
Pod undocumented
307 1 my ($self, $enabled) = @_;
308 1 ▶ $enabled //= 1;
Condition50%1/2
$enabled //= 1
l!l
10
MC/DC0%0/1
$enabled //= 1
$enabled
Truth table50%1/2
A
A= $enabled
Aresult
11
00
309 1 ▶ return $self->add_action('extensive_data', $enabled ? JSON::true : JSON::false);
Branch: 1 branch
BranchTrueFalseTotal
$enabled ? : 1 0 1
310 }
311  
312 1 ▶sub update_settings {
Subroutine update_settings: called CC=1 SCAR=0.0
Pod undocumented
313 1 my ($self, $settings) = @_;
314 1 return $self->add_action('settings', $settings);
315 }
316  
317 # --- Advanced ---
318  
319 9 ▶sub execute_swml {
Subroutine execute_swml: called CC=6 SCAR=18.2
Pod undocumented
320 9 my ($self, $swml_content, %opts) = @_;
321 9 ▶ my $transfer = $opts{transfer} // 0;
Condition100%2/2
$opts{"transfer"} // 0
l!l
18
MC/DC100%1/1
$opts{"transfer"} // 0
$opts{"transfer"}
Truth table100%2/2
A
A= $opts{"transfer"}
Aresult
11
00
322  
323 9 my $swml_data;
324 9 ▶ if (ref $swml_content eq 'HASH') {
Branch: 2 branches
BranchTrueFalseTotal
if (ref $swml_content eq 'HASH') { } 8 1 9
elsif (not ref $swml_content) { } 1 0 1
325 # Deep-copy to avoid mutating caller's data
326 8 $swml_data = JSON::decode_json(JSON::encode_json($swml_content));
327 } elsif (!ref $swml_content) {
328 # String - try parsing as JSON
329 1 eval {
330 1 $swml_data = JSON::decode_json($swml_content);
331 };
332 1 ▶ if ($@) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 1 1
333 0 $swml_data = { raw_swml => $swml_content };
334 }
335 } else {
336 0 die "swml_content must be a string or hashref";
337 }
338  
339 9 ▶ if ($transfer) {
Branch: 1 branch
BranchTrueFalseTotal
if ($transfer) 1 8 9
340 1 $swml_data->{transfer} = 'true';
341 }
342  
343 9 return $self->add_action('SWML', $swml_data);
344 }
345  
346 0 ▶sub join_conference {
Subroutine join_conference: not called CC=10 SCAR=47.0
Pod undocumented
347 0 my ($self, $name, %opts) = @_;
348 0 ▶ die "name cannot be empty" unless defined $name && length $name;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $name and length $name 0 0 0
Condition0%0/3
defined $name and length $name
!ll&&!rl&&r
000
MC/DC0%0/2
defined $name and length $name
defined $name length $name
Truth table0%0/3
A and B
A= defined $nameB= length $name
ABresult
0X0
100
111
349  
350 0 ▶ my $muted = $opts{muted} // 0;
Condition0%0/2
$opts{"muted"} // 0
l!l
00
MC/DC0%0/1
$opts{"muted"} // 0
$opts{"muted"}
Truth table0%0/2
A
A= $opts{"muted"}
Aresult
11
00
351 0 ▶ my $beep = $opts{beep} // 'true';
Condition0%0/2
$opts{"beep"} // "true"
l!l
00
MC/DC0%0/1
$opts{"beep"} // "true"
$opts{"beep"}
Truth table0%0/2
A
A= $opts{"beep"}
Aresult
11
00
352  
353 # Simple form: no options set
354 0 ▶ if (!$muted && $beep eq 'true' && !keys %opts) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $muted and $beep eq "true" and not keys %opts) 0 0 0
Condition0%0/6
not $muted and $beep eq "true" and not keys %opts
!ll&&!rl&&r
000
not $muted and $beep eq "true"
!ll&&!rl&&r
000
MC/DC0%0/3
not $muted and $beep eq "true" and not keys %opts
not $muted $beep eq "true" not keys %opts
Truth table0%0/4
not(A) and B and not(C)
A= not $mutedB= $beep eq "true"C= not keys %opts
ABCresult
0XX0
10X0
1100
1111
355 0 my $swml_doc = {
356 version => '1.0.0',
357 sections => { main => [{ join_conference => $name }] },
358 };
359 0 return $self->execute_swml($swml_doc);
360 }
361  
362 0 my %params = (name => $name);
363 0 ▶ $params{muted} = JSON::true if $muted;
Branch: 1 branch
BranchTrueFalseTotal
if $muted 0 0 0
364 0 ▶ $params{beep} = $beep if $beep ne 'true';
Branch: 1 branch
BranchTrueFalseTotal
if $beep ne "true" 0 0 0
365  
366 0 my $swml_doc = {
367 version => '1.0.0',
368 sections => { main => [{ join_conference => \%params }] },
369 };
370 0 return $self->execute_swml($swml_doc);
371 }
372  
373 1 ▶sub join_room {
Subroutine join_room: called CC=1 SCAR=0.0
Pod undocumented
374 1 my ($self, $name) = @_;
375 1 my $swml_doc = {
376 version => '1.0.0',
377 sections => { main => [{ join_room => { name => $name } }] },
378 };
379 1 return $self->execute_swml($swml_doc);
380 }
381  
382 1 ▶sub sip_refer {
Subroutine sip_refer: called CC=1 SCAR=0.0
Pod undocumented
383 1 my ($self, $to_uri) = @_;
384 1 my $swml_doc = {
385 version => '1.0.0',
386 sections => { main => [{ sip_refer => { to_uri => $to_uri } }] },
387 };
388 1 return $self->execute_swml($swml_doc);
389 }
390  
391 0 ▶sub tap {
Subroutine tap: not called CC=11 SCAR=48.8
Pod undocumented
392 0 my ($self, $uri, %opts) = @_;
393 0 my $control_id = $opts{control_id};
394 0 ▶ my $direction = $opts{direction} // 'both';
Condition0%0/2
$opts{"direction"} // "both"
l!l
00
MC/DC0%0/1
$opts{"direction"} // "both"
$opts{"direction"}
Truth table0%0/2
A
A= $opts{"direction"}
Aresult
11
00
395 0 ▶ my $codec = $opts{codec} // 'PCMU';
Condition0%0/2
$opts{"codec"} // "PCMU"
l!l
00
MC/DC0%0/1
$opts{"codec"} // "PCMU"
$opts{"codec"}
Truth table0%0/2
A
A= $opts{"codec"}
Aresult
11
00
396  
397 0 ▶ die "direction must be 'speak', 'hear', or 'both'"
Branch: 1 branch
BranchTrueFalseTotal
unless $direction eq "speak" or $direction eq "hear" or $direction eq "both" 0 0 0
Condition0%0/6
$direction eq "speak" or $direction eq "hear" or $direction eq "both"
l!l&&r!l&&!r
000
$direction eq "speak" or $direction eq "hear"
l!l&&r!l&&!r
000
MC/DC0%0/3
$direction eq "speak" or $direction eq "hear" or $direction eq "both"
$direction eq "speak" $direction eq "hear" $direction eq "both"
Truth table0%0/4
A or B or C
A= $direction eq "speak"B= $direction eq "hear"C= $direction eq "both"
ABCresult
1XX1
01X1
0011
0000
398 unless $direction eq 'speak' || $direction eq 'hear' || $direction eq 'both';
399 0 ▶ die "codec must be 'PCMU' or 'PCMA'"
Branch: 1 branch
BranchTrueFalseTotal
unless $codec eq "PCMU" or $codec eq "PCMA" 0 0 0
Condition0%0/3
$codec eq "PCMU" or $codec eq "PCMA"
l!l&&r!l&&!r
000
MC/DC0%0/2
$codec eq "PCMU" or $codec eq "PCMA"
$codec eq "PCMU" $codec eq "PCMA"
Truth table0%0/3
A or B
A= $codec eq "PCMU"B= $codec eq "PCMA"
ABresult
1X1
011
000
400 unless $codec eq 'PCMU' || $codec eq 'PCMA';
401  
402 0 my %params = (uri => $uri);
403 0 ▶ $params{control_id} = $control_id if $control_id;
Branch: 1 branch
BranchTrueFalseTotal
if $control_id 0 0 0
404 0 ▶ $params{direction} = $direction if $direction ne 'both';
Branch: 1 branch
BranchTrueFalseTotal
if $direction ne "both" 0 0 0
405 0 ▶ $params{codec} = $codec if $codec ne 'PCMU';
Branch: 1 branch
BranchTrueFalseTotal
if $codec ne "PCMU" 0 0 0
406  
407 0 my $swml_doc = {
408 version => '1.0.0',
409 sections => { main => [{ tap => \%params }] },
410 };
411 0 return $self->execute_swml($swml_doc);
412 }
413  
414 0 ▶sub stop_tap {
Subroutine stop_tap: not called CC=2 SCAR=17.9
Pod undocumented
415 0 my ($self, %opts) = @_;
416 0 my $control_id = $opts{control_id};
417 0 my %params;
418 0 ▶ $params{control_id} = $control_id if $control_id;
Branch: 1 branch
BranchTrueFalseTotal
if $control_id 0 0 0
419  
420 0 my $swml_doc = {
421 version => '1.0.0',
422 sections => { main => [{ stop_tap => \%params }] },
423 };
424 0 return $self->execute_swml($swml_doc);
425 }
426  
427 0 ▶sub send_sms {
Subroutine send_sms: not called CC=9 SCAR=45.0
Pod undocumented
428 0 my ($self, %opts) = @_;
429 0 ▶ my $to_number = $opts{to_number} // die "to_number is required";
Condition0%0/2
$opts{"to_number"} // die("to_number is required")
l!l
00
MC/DC0%0/1
$opts{"to_number"} // die("to_number is required")
$opts{"to_number"}
Truth table0%0/2
A
A= $opts{"to_number"}
Aresult
11
00
430 0 ▶ my $from_number = $opts{from_number} // die "from_number is required";
Condition0%0/2
$opts{"from_number"} // die("from_number is required")
l!l
00
MC/DC0%0/1
$opts{"from_number"} // die("from_number is required")
$opts{"from_number"}
Truth table0%0/2
A
A= $opts{"from_number"}
Aresult
11
00
431 0 my $body = $opts{body};
432 0 my $media = $opts{media};
433 0 my $tags = $opts{tags};
434 0 my $region = $opts{region};
435  
436 0 ▶ die "Either body or media must be provided" unless $body || $media;
Branch: 1 branch
BranchTrueFalseTotal
unless $body or $media 0 0 0
Condition0%0/3
$body or $media
l!l&&r!l&&!r
000
MC/DC0%0/2
$body or $media
$body $media
Truth table0%0/3
A or B
A= $bodyB= $media
ABresult
1X1
011
000
437  
438 0 my %sms_params = (
439 to_number => $to_number,
440 from_number => $from_number,
441 );
442 0 ▶ $sms_params{body} = $body if $body;
Branch: 1 branch
BranchTrueFalseTotal
if $body 0 0 0
443 0 ▶ $sms_params{media} = $media if $media;
Branch: 1 branch
BranchTrueFalseTotal
if $media 0 0 0
444 0 ▶ $sms_params{tags} = $tags if $tags;
Branch: 1 branch
BranchTrueFalseTotal
if $tags 0 0 0
445 0 ▶ $sms_params{region} = $region if $region;
Branch: 1 branch
BranchTrueFalseTotal
if $region 0 0 0
446  
447 0 my $swml_doc = {
448 version => '1.0.0',
449 sections => { main => [{ send_sms => \%sms_params }] },
450 };
451 0 return $self->execute_swml($swml_doc);
452 }
453  
454 0 ▶sub pay {
Subroutine pay: not called CC=23 SCAR=63.1
Pod undocumented
455 0 my ($self, %opts) = @_;
456 0 ▶ my $connector_url = $opts{payment_connector_url} // die "payment_connector_url required";
Condition0%0/2
$opts{"payment_connector_url"} // die("payment_connector_url required")
l!l
00
MC/DC0%0/1
$opts{"payment_connector_url"} // die("payment_connector_url required")
$opts{"payment_connector_url"}
Truth table0%0/2
A
A= $opts{"payment_connector_url"}
Aresult
11
00
457 0 ▶ my $input_method = $opts{input_method} // 'dtmf';
Condition0%0/2
$opts{"input_method"} // "dtmf"
l!l
00
MC/DC0%0/1
$opts{"input_method"} // "dtmf"
$opts{"input_method"}
Truth table0%0/2
A
A= $opts{"input_method"}
Aresult
11
00
458 0 ▶ my $timeout = $opts{timeout} // 5;
Condition0%0/2
$opts{"timeout"} // 5
l!l
00
MC/DC0%0/1
$opts{"timeout"} // 5
$opts{"timeout"}
Truth table0%0/2
A
A= $opts{"timeout"}
Aresult
11
00
459 0 ▶ my $max_attempts = $opts{max_attempts} // 1;
Condition0%0/2
$opts{"max_attempts"} // 1
l!l
00
MC/DC0%0/1
$opts{"max_attempts"} // 1
$opts{"max_attempts"}
Truth table0%0/2
A
A= $opts{"max_attempts"}
Aresult
11
00
460 0 ▶ my $ai_response = $opts{ai_response} // 'The payment status is ${pay_result}, do not mention anything else about collecting payment if successful.';
Condition0%0/2
$opts{"ai_response"} // "The payment status is \${pay_result}, do not mention anything else about collecting payment if successful."
l!l
00
MC/DC0%0/1
$opts{"ai_response"} // "The payment status is \${pay_result}, do not mention anything else about collecting payment if successful."
$opts{"ai_response"}
Truth table0%0/2
A
A= $opts{"ai_response"}
Aresult
11
00
461  
462 my %pay_params = (
463 payment_connector_url => $connector_url,
464 input => $input_method,
465 payment_method => $opts{payment_method} // 'credit-card',
466 timeout => "$timeout",
467 max_attempts => "$max_attempts",
468 security_code => (($opts{security_code} // 1) ? 'true' : 'false'),
469 token_type => $opts{token_type} // 'reusable',
470 currency => $opts{currency} // 'usd',
471 language => $opts{language} // 'en-US',
472 voice => $opts{voice} // 'woman',
473 0 ▶ valid_card_types => $opts{valid_card_types} // 'visa mastercard amex',
Branch: 1 branch
BranchTrueFalseTotal
$opts{'security_code'} // 1 ? : 0 0 0
Condition0%0/14
$opts{"payment_method"} // "credit-card"
l!l
00
$opts{"security_code"} // 1
l!l
00
$opts{"token_type"} // "reusable"
l!l
00
$opts{"currency"} // "usd"
l!l
00
$opts{"language"} // "en-US"
l!l
00
$opts{"voice"} // "woman"
l!l
00
$opts{"valid_card_types"} // "visa mastercard amex"
l!l
00
MC/DC0%0/1
$opts{"payment_method"} // "credit-card"
$opts{"payment_method"}
MC/DC0%0/1
$opts{"security_code"} // 1
$opts{"security_code"}
MC/DC0%0/1
$opts{"token_type"} // "reusable"
$opts{"token_type"}
MC/DC0%0/1
$opts{"currency"} // "usd"
$opts{"currency"}
MC/DC0%0/1
$opts{"language"} // "en-US"
$opts{"language"}
MC/DC0%0/1
$opts{"voice"} // "woman"
$opts{"voice"}
MC/DC0%0/1
$opts{"valid_card_types"} // "visa mastercard amex"
$opts{"valid_card_types"}
Truth table0%0/2
A
A= $opts{"payment_method"}
Aresult
11
00
Truth table0%0/2
A
A= $opts{"security_code"}
Aresult
11
00
Truth table0%0/2
A
A= $opts{"token_type"}
Aresult
11
00
Truth table0%0/2
A
A= $opts{"currency"}
Aresult
11
00
Truth table0%0/2
A
A= $opts{"language"}
Aresult
11
00
Truth table0%0/2
A
A= $opts{"voice"}
Aresult
11
00
Truth table0%0/2
A
A= $opts{"valid_card_types"}
Aresult
11
00
474 );
475  
476 0 ▶ my $postal = $opts{postal_code} // 1;
Condition0%0/2
$opts{"postal_code"} // 1
l!l
00
MC/DC0%0/1
$opts{"postal_code"} // 1
$opts{"postal_code"}
Truth table0%0/2
A
A= $opts{"postal_code"}
Aresult
11
00
477 0 ▶ if (ref $postal || $postal =~ /^[01]$/) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $postal or $postal =~ /^[01]$/) { } 0 0 0
Condition0%0/3
ref $postal or $postal =~ /^[01]$/
l!l&&r!l&&!r
000
MC/DC0%0/2
ref $postal or $postal =~ /^[01]$/
ref $postal $postal =~ /^[01]$/
Truth table0%0/3
A or B
A= ref $postalB= $postal =~ /^[01]$/
ABresult
1X1
011
000
478 0 ▶ $pay_params{postal_code} = $postal ? 'true' : 'false';
Branch: 1 branch
BranchTrueFalseTotal
$postal ? : 0 0 0
479 } else {
480 0 $pay_params{postal_code} = $postal;
481 }
482  
483 0 ▶ $pay_params{status_url} = $opts{status_url} if $opts{status_url};
Branch: 1 branch
BranchTrueFalseTotal
if $opts{"status_url"} 0 0 0
484 0 ▶ $pay_params{charge_amount} = $opts{charge_amount} if $opts{charge_amount};
Branch: 1 branch
BranchTrueFalseTotal
if $opts{"charge_amount"} 0 0 0
485 0 ▶ $pay_params{description} = $opts{description} if $opts{description};
Branch: 1 branch
BranchTrueFalseTotal
if $opts{"description"} 0 0 0
486 0 ▶ $pay_params{parameters} = $opts{parameters} if $opts{parameters};
Branch: 1 branch
BranchTrueFalseTotal
if $opts{"parameters"} 0 0 0
487 0 ▶ $pay_params{prompts} = $opts{prompts} if $opts{prompts};
Branch: 1 branch
BranchTrueFalseTotal
if $opts{"prompts"} 0 0 0
488  
489 0 my $swml_doc = {
490 version => '1.0.0',
491 sections => {
492 main => [
493 { set => { ai_response => $ai_response } },
494 { pay => \%pay_params },
495 ],
496 },
497 };
498 0 return $self->execute_swml($swml_doc);
499 }
500  
501 # --- RPC ---
502  
503 4 ▶sub execute_rpc {
Subroutine execute_rpc: called CC=5 SCAR=16.3
Pod undocumented
504 4 my ($self, %opts) = @_;
505 4 ▶ my $method = $opts{method} // die "method is required";
Condition50%1/2
$opts{"method"} // die("method is required")
l!l
40
MC/DC0%0/1
$opts{"method"} // die("method is required")
$opts{"method"}
Truth table50%1/2
A
A= $opts{"method"}
Aresult
11
00
506 4 my $params = $opts{params};
507 4 my $call_id = $opts{call_id};
508 4 my $node_id = $opts{node_id};
509  
510 4 my %rpc_params = (method => $method);
511 4 ▶ $rpc_params{call_id} = $call_id if $call_id;
Branch: 1 branch
BranchTrueFalseTotal
if $call_id 2 2 4
512 4 ▶ $rpc_params{node_id} = $node_id if $node_id;
Branch: 1 branch
BranchTrueFalseTotal
if $node_id 0 4 4
513 4 ▶ $rpc_params{params} = $params if $params;
Branch: 1 branch
BranchTrueFalseTotal
if $params 4 0 4
514  
515 4 my $swml_doc = {
516 version => '1.0.0',
517 sections => { main => [{ execute_rpc => \%rpc_params }] },
518 };
519 4 return $self->execute_swml($swml_doc);
520 }
521  
522 1 ▶sub rpc_dial {
Subroutine rpc_dial: called CC=5 SCAR=17.2
Pod undocumented
523 1 my ($self, %opts) = @_;
524 1 ▶ my $to_number = $opts{to_number} // die "to_number is required";
Condition50%1/2
$opts{"to_number"} // die("to_number is required")
l!l
10
MC/DC0%0/1
$opts{"to_number"} // die("to_number is required")
$opts{"to_number"}
Truth table50%1/2
A
A= $opts{"to_number"}
Aresult
11
00
525 1 ▶ my $from_number = $opts{from_number} // die "from_number is required";
Condition50%1/2
$opts{"from_number"} // die("from_number is required")
l!l
10
MC/DC0%0/1
$opts{"from_number"} // die("from_number is required")
$opts{"from_number"}
Truth table50%1/2
A
A= $opts{"from_number"}
Aresult
11
00
526 1 ▶ my $dest_swml = $opts{dest_swml} // die "dest_swml is required";
Condition50%1/2
$opts{"dest_swml"} // die("dest_swml is required")
l!l
10
MC/DC0%0/1
$opts{"dest_swml"} // die("dest_swml is required")
$opts{"dest_swml"}
Truth table50%1/2
A
A= $opts{"dest_swml"}
Aresult
11
00
527 1 ▶ my $device_type = $opts{device_type} // 'phone';
Condition50%1/2
$opts{"device_type"} // "phone"
l!l
01
MC/DC0%0/1
$opts{"device_type"} // "phone"
$opts{"device_type"}
Truth table50%1/2
A
A= $opts{"device_type"}
Aresult
11
00
528  
529 1 return $self->execute_rpc(
530 method => 'dial',
531 params => {
532 devices => {
533 type => $device_type,
534 params => {
535 to_number => $to_number,
536 from_number => $from_number,
537 },
538 },
539 dest_swml => $dest_swml,
540 },
541 );
542 }
543  
544 1 ▶sub rpc_ai_message {
Subroutine rpc_ai_message: called CC=4 SCAR=14.6
Pod undocumented
545 1 my ($self, %opts) = @_;
546 1 ▶ my $call_id = $opts{call_id} // die "call_id is required";
Condition50%1/2
$opts{"call_id"} // die("call_id is required")
l!l
10
MC/DC0%0/1
$opts{"call_id"} // die("call_id is required")
$opts{"call_id"}
Truth table50%1/2
A
A= $opts{"call_id"}
Aresult
11
00
547 1 ▶ my $message_text = $opts{message_text} // die "message_text is required";
Condition50%1/2
$opts{"message_text"} // die("message_text is required")
l!l
10
MC/DC0%0/1
$opts{"message_text"} // die("message_text is required")
$opts{"message_text"}
Truth table50%1/2
A
A= $opts{"message_text"}
Aresult
11
00
548 1 ▶ my $role = $opts{role} // 'system';
Condition50%1/2
$opts{"role"} // "system"
l!l
01
MC/DC0%0/1
$opts{"role"} // "system"
$opts{"role"}
Truth table50%1/2
A
A= $opts{"role"}
Aresult
11
00
549  
550 1 return $self->execute_rpc(
551 method => 'ai_message',
552 call_id => $call_id,
553 params => {
554 role => $role,
555 message_text => $message_text,
556 },
557 );
558 }
559  
560 1 ▶sub rpc_ai_unhold {
Subroutine rpc_ai_unhold: called CC=2 SCAR=7.1
Pod undocumented
561 1 my ($self, %opts) = @_;
562 1 ▶ my $call_id = $opts{call_id} // die "call_id is required";
Condition50%1/2
$opts{"call_id"} // die("call_id is required")
l!l
10
MC/DC0%0/1
$opts{"call_id"} // die("call_id is required")
$opts{"call_id"}
Truth table50%1/2
A
A= $opts{"call_id"}
Aresult
11
00
563  
564 1 return $self->execute_rpc(
565 method => 'ai_unhold',
566 call_id => $call_id,
567 params => {},
568 );
569 }
570  
571 1 ▶sub simulate_user_input {
Subroutine simulate_user_input: called CC=1 SCAR=0.0
Pod undocumented
572 1 my ($self, $text) = @_;
573 1 return $self->add_action('user_input', $text);
574 }
575  
576 # --- Payment helpers (class methods) ---
577  
578 1 ▶sub create_payment_prompt {
Subroutine create_payment_prompt: called CC=5 SCAR=16.7
Pod undocumented
579 1 my ($class_or_self, %opts) = @_;
580 1 ▶ my $for_situation = $opts{for_situation} // die "for_situation is required";
Condition50%1/2
$opts{"for_situation"} // die("for_situation is required")
l!l
10
MC/DC0%0/1
$opts{"for_situation"} // die("for_situation is required")
$opts{"for_situation"}
Truth table50%1/2
A
A= $opts{"for_situation"}
Aresult
11
00
581 1 ▶ my $actions = $opts{actions} // die "actions is required";
Condition50%1/2
$opts{"actions"} // die("actions is required")
l!l
10
MC/DC0%0/1
$opts{"actions"} // die("actions is required")
$opts{"actions"}
Truth table50%1/2
A
A= $opts{"actions"}
Aresult
11
00
582 1 my $card_type = $opts{card_type};
583 1 my $error_type = $opts{error_type};
584  
585 1 my %prompt = (
586 for => $for_situation,
587 actions => $actions,
588 );
589 1 ▶ $prompt{card_type} = $card_type if $card_type;
Branch: 1 branch
BranchTrueFalseTotal
if $card_type 1 0 1
590 1 ▶ $prompt{error_type} = $error_type if $error_type;
Branch: 1 branch
BranchTrueFalseTotal
if $error_type 0 1 1
591  
592 1 return \%prompt;
593 }
594  
595 1 ▶sub create_payment_action {
Subroutine create_payment_action: called CC=1 SCAR=0.0
Pod undocumented
596 1 my ($class_or_self, $action_type, $phrase) = @_;
597 1 return { type => $action_type, phrase => $phrase };
598 }
599  
600 1 ▶sub create_payment_parameter {
Subroutine create_payment_parameter: called CC=1 SCAR=0.0
Pod undocumented
601 1 my ($class_or_self, $name, $value) = @_;
602 1 return { name => $name, value => $value };
603 }
604  
605 # --- Serialization ---
606  
607 68 ▶sub to_hash {
Subroutine to_hash: called CC=5 SCAR=16.1
Pod undocumented
608 68 my ($self) = @_;
609 68 my %result;
610  
611 68 ▶ $result{response} = $self->response if length $self->response;
Branch: 1 branch
BranchTrueFalseTotal
if length $self->response 67 1 68
612  
613 68 ▶ if (@{ $self->action }) {
Branch: 1 branch
BranchTrueFalseTotal
if (@{$self->action;}) 45 23 68
614 45 $result{action} = $self->action;
615 45 ▶ $result{post_process} = JSON::true if $self->post_process;
Branch: 1 branch
BranchTrueFalseTotal
if $self->post_process 2 43 45
616 }
617  
618 # Ensure at least one of response or action
619 68 ▶ if (!keys %result) {
Branch: 1 branch
BranchTrueFalseTotal
unless (keys %result) 1 67 68
620 1 $result{response} = 'Action completed.';
621 }
622  
623 68 return \%result;
624 }
625  
626 0 ▶sub to_json {
Subroutine to_json: not called CC=1 SCAR=6.9
Pod undocumented
627 0 my ($self) = @_;
628 0 return JSON::encode_json($self->to_hash);
629 }
630  
631 16 1;
« blib/lib/SignalWire/Relay/Client.pm ↑ Summary blib/lib/SignalWire/Server/AgentServer.pm »