« blib/lib/SignalWire/REST/Namespaces/Calling.pm
↑ Summary
blib/lib/SignalWire/Skills/Builtin/ApiNinjasTrivia.pm »
| 1 | package SignalWire; | ||||||||||||||||||||||||||||||||||||||||||
| 2 | 1 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 3 | 1 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||||||||||||||||
| 5 | 1 | our $VERSION = '2.0.2'; | |||||||||||||||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||||||||||||||||
| 7 | 1 | ▶ | use SignalWire::Logging; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 8 | 1 | ▶ | use SignalWire::SWML::Document; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 9 | 1 | ▶ | use SignalWire::SWML::Schema; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 10 | 1 | ▶ | use SignalWire::SWML::Service; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 11 | 1 | ▶ | use SignalWire::SWAIG::FunctionResult; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 12 | 1 | ▶ | use SignalWire::Security::SessionManager; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 13 | 1 | ▶ | use SignalWire::DataMap; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 14 | 1 | ▶ | use SignalWire::Contexts; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||||||||||||||||
| 16 | # ------------------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||||||||||
| 17 | # Top-level convenience entry points | ||||||||||||||||||||||||||||||||||||||||||
| 18 | # | ||||||||||||||||||||||||||||||||||||||||||
| 19 | # Mirror Python's package-level signalwire/__init__.py — RestClient | ||||||||||||||||||||||||||||||||||||||||||
| 20 | # factory + skill registry helpers (register_skill, add_skill_directory, | ||||||||||||||||||||||||||||||||||||||||||
| 21 | # list_skills_with_params). These delegate to the underlying classes. | ||||||||||||||||||||||||||||||||||||||||||
| 22 | # ------------------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||||||||||||||||
| 24 | # Singleton SkillRegistry "instance" — Perl's SkillRegistry stores state | ||||||||||||||||||||||||||||||||||||||||||
| 25 | # in package-level variables, so the helpers below operate on the class | ||||||||||||||||||||||||||||||||||||||||||
| 26 | # directly rather than building a Moo-style instance. This sub returns | ||||||||||||||||||||||||||||||||||||||||||
| 27 | # the class name (good enough for ->method() invocations) and exists so | ||||||||||||||||||||||||||||||||||||||||||
| 28 | # tests can introspect singleton state via the same accessor used at | ||||||||||||||||||||||||||||||||||||||||||
| 29 | # runtime. | ||||||||||||||||||||||||||||||||||||||||||
| 30 | 3 | ▶ | sub _singleton_registry { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_singleton_registry: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 31 | 3 | require SignalWire::Skills::SkillRegistry; | |||||||||||||||||||||||||||||||||||||||||
| 32 | 3 | return 'SignalWire::Skills::SkillRegistry'; | |||||||||||||||||||||||||||||||||||||||||
| 33 | } | ||||||||||||||||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||||||||||||||||
| 35 | # Construct a SignalWire::REST::RestClient instance. | ||||||||||||||||||||||||||||||||||||||||||
| 36 | # | ||||||||||||||||||||||||||||||||||||||||||
| 37 | # Mirrors Python's top-level ``signalwire.RestClient(*args, **kwargs)`` | ||||||||||||||||||||||||||||||||||||||||||
| 38 | # factory — a thin wrapper that lazy-loads ``SignalWire::REST::RestClient`` | ||||||||||||||||||||||||||||||||||||||||||
| 39 | # and calls its constructor. Supports either positional credentials | ||||||||||||||||||||||||||||||||||||||||||
| 40 | # (project, token, host) or hash-style keyword credentials. | ||||||||||||||||||||||||||||||||||||||||||
| 41 | # | ||||||||||||||||||||||||||||||||||||||||||
| 42 | # The signature is declared with ``my (@args, %kwargs) = @_;`` so the | ||||||||||||||||||||||||||||||||||||||||||
| 43 | # audit's regex-based dumper sees the canonical variadic shape (Perl's | ||||||||||||||||||||||||||||||||||||||||||
| 44 | # slurpy array + slurpy hash mirror Python's ``*args, **kwargs``). At | ||||||||||||||||||||||||||||||||||||||||||
| 45 | # runtime, only one of @args / %kwargs will actually be populated since | ||||||||||||||||||||||||||||||||||||||||||
| 46 | # Perl's slurpy semantics greedily consume the remaining arglist into | ||||||||||||||||||||||||||||||||||||||||||
| 47 | # the array; keyword-style callers pass an even number of args (no | ||||||||||||||||||||||||||||||||||||||||||
| 48 | # leading positional) so @args becomes the kwargs pairlist instead. | ||||||||||||||||||||||||||||||||||||||||||
| 49 | 3 | ▶ | sub RestClient { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
RestClient: called CC=4 SCAR=14.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 50 | # Audit-shape declaration: declare both slurpy positional and slurpy | ||||||||||||||||||||||||||||||||||||||||||
| 51 | # hash so the surface enumerator sees the canonical ``*args, **kwargs`` | ||||||||||||||||||||||||||||||||||||||||||
| 52 | # shape Python uses. We don't actually rely on %kwargs at runtime — | ||||||||||||||||||||||||||||||||||||||||||
| 53 | # Perl's slurpy-array semantics consume everything into @args, so | ||||||||||||||||||||||||||||||||||||||||||
| 54 | # %kwargs always ends up empty. Real argument splitting happens below. | ||||||||||||||||||||||||||||||||||||||||||
| 55 | 3 | my (@args, %kwargs) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 56 | 3 | require SignalWire::REST::RestClient; | |||||||||||||||||||||||||||||||||||||||||
| 57 | # Three bare strings -> positional (project, token, host); anything | ||||||||||||||||||||||||||||||||||||||||||
| 58 | # else is a hash-style keyword args list passed via @_. | ||||||||||||||||||||||||||||||||||||||||||
| 59 | 3 | my @raw = @_; | |||||||||||||||||||||||||||||||||||||||||
| 60 | 3 | ▶ | if (@raw == 3 && !ref($raw[0]) && $raw[0] !~ /^(?:project|token|host)$/) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%4/6
@raw == 3 and not ref $raw[0] and not $raw[0] =~ /^(?:project|token|host)$/
@raw == 3 and not ref $raw[0]
MC/DC33%1/3
@raw == 3 and not ref $raw[0] and not $raw[0] =~ /^(?:project|token|host)$/
@raw == 3
not ref $raw[0]
not $raw[0] =~ /^(?:project|token|host)$/
Truth table50%2/4
A and not(B) and not(C)
A= @raw == 3B= not ref $raw[0]C= not $raw[0] =~ /^(?:project|token|host)$/
| |||||||||||||||||||||||||||||||||||||||||||
| 61 | 1 | return SignalWire::REST::RestClient->new( | |||||||||||||||||||||||||||||||||||||||||
| 62 | project => $raw[0], | ||||||||||||||||||||||||||||||||||||||||||
| 63 | token => $raw[1], | ||||||||||||||||||||||||||||||||||||||||||
| 64 | host => $raw[2], | ||||||||||||||||||||||||||||||||||||||||||
| 65 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 66 | } | ||||||||||||||||||||||||||||||||||||||||||
| 67 | 2 | return SignalWire::REST::RestClient->new(@raw); | |||||||||||||||||||||||||||||||||||||||||
| 68 | } | ||||||||||||||||||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||||||||||||||||
| 70 | # Register a custom skill class with the global skill registry. | ||||||||||||||||||||||||||||||||||||||||||
| 71 | # | ||||||||||||||||||||||||||||||||||||||||||
| 72 | # Mirrors Python's ``signalwire.register_skill(skill_class)``. The class | ||||||||||||||||||||||||||||||||||||||||||
| 73 | # is expected to expose a ``::skill_name`` accessor or a ``SKILL_NAME`` | ||||||||||||||||||||||||||||||||||||||||||
| 74 | # constant so the registration key can be derived. | ||||||||||||||||||||||||||||||||||||||||||
| 75 | 1 | ▶ | sub register_skill { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
register_skill: called CC=3 SCAR=12.6
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 76 | 1 | my ($skill_class) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 77 | 1 | require SignalWire::Skills::SkillRegistry; | |||||||||||||||||||||||||||||||||||||||||
| 78 | 1 | my $name; | |||||||||||||||||||||||||||||||||||||||||
| 79 | 1 | ▶ | if ($skill_class->can('skill_name')) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 80 | 1 | $name = $skill_class->skill_name; | |||||||||||||||||||||||||||||||||||||||||
| 81 | 0 | } elsif (defined &{"${skill_class}::SKILL_NAME"}) { | |||||||||||||||||||||||||||||||||||||||||
| 82 | 1 | ▶ | no strict 'refs'; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 83 | 0 | $name = ${"${skill_class}::SKILL_NAME"}; | |||||||||||||||||||||||||||||||||||||||||
| 84 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 85 | 0 | die "skill class $skill_class must define ::skill_name or SKILL_NAME\n"; | |||||||||||||||||||||||||||||||||||||||||
| 86 | } | ||||||||||||||||||||||||||||||||||||||||||
| 87 | 1 | SignalWire::Skills::SkillRegistry->register_skill($name, $skill_class); | |||||||||||||||||||||||||||||||||||||||||
| 88 | 1 | return; | |||||||||||||||||||||||||||||||||||||||||
| 89 | } | ||||||||||||||||||||||||||||||||||||||||||
| 90 | |||||||||||||||||||||||||||||||||||||||||||
| 91 | # Add a directory to search for skills. | ||||||||||||||||||||||||||||||||||||||||||
| 92 | # | ||||||||||||||||||||||||||||||||||||||||||
| 93 | # Mirrors Python's ``signalwire.add_skill_directory(path)`` — delegates | ||||||||||||||||||||||||||||||||||||||||||
| 94 | # to the singleton SkillRegistry instance so third-party skill | ||||||||||||||||||||||||||||||||||||||||||
| 95 | # collections can be registered by path. Subsequent calls accumulate | ||||||||||||||||||||||||||||||||||||||||||
| 96 | # (de-duplicated) into a shared external paths list. | ||||||||||||||||||||||||||||||||||||||||||
| 97 | 2 | ▶ | sub add_skill_directory { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
add_skill_directory: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 98 | 2 | my ($path) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 99 | 2 | return _singleton_registry()->add_skill_directory($path); | |||||||||||||||||||||||||||||||||||||||||
| 100 | } | ||||||||||||||||||||||||||||||||||||||||||
| 101 | |||||||||||||||||||||||||||||||||||||||||||
| 102 | # Get complete schema for all available skills. | ||||||||||||||||||||||||||||||||||||||||||
| 103 | # | ||||||||||||||||||||||||||||||||||||||||||
| 104 | # Mirrors Python's ``signalwire.list_skills_with_params()``. Returns a | ||||||||||||||||||||||||||||||||||||||||||
| 105 | # hashref keyed by skill name where each value contains parameter | ||||||||||||||||||||||||||||||||||||||||||
| 106 | # metadata. Useful for GUI configuration tools, API documentation, or | ||||||||||||||||||||||||||||||||||||||||||
| 107 | # programmatic skill discovery. | ||||||||||||||||||||||||||||||||||||||||||
| 108 | 1 | ▶ | sub list_skills_with_params { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
list_skills_with_params: called CC=2 SCAR=9.2
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 109 | 1 | require SignalWire::Skills::SkillRegistry; | |||||||||||||||||||||||||||||||||||||||||
| 110 | 1 | ▶ | if (SignalWire::Skills::SkillRegistry->can('get_all_skills_schema')) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 111 | 1 | return SignalWire::Skills::SkillRegistry->get_all_skills_schema; | |||||||||||||||||||||||||||||||||||||||||
| 112 | } | ||||||||||||||||||||||||||||||||||||||||||
| 113 | # Fallback: list_skills returns names; pair them with empty params. | ||||||||||||||||||||||||||||||||||||||||||
| 114 | 0 | my $names = SignalWire::Skills::SkillRegistry->list_skills; | |||||||||||||||||||||||||||||||||||||||||
| 115 | 0 | return { map { $_ => { name => $_, parameters => {} } } @$names }; | |||||||||||||||||||||||||||||||||||||||||
| 116 | } | ||||||||||||||||||||||||||||||||||||||||||
| 117 | |||||||||||||||||||||||||||||||||||||||||||
| 118 | 1 | 1; | |||||||||||||||||||||||||||||||||||||||||
| 119 | |||||||||||||||||||||||||||||||||||||||||||
| 120 | __END__ | ||||||||||||||||||||||||||||||||||||||||||