blib/lib/SignalWire/Agents/Skills/SkillRegistry.pm

filter: Statementstmt 100% 31 / 31 Branchbran 100% 6 / 6 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 8 / 8 Podpod 0.0% 0 / 4 totaltotal 91.8% 45 / 49 CC 5 SCAR 7.7
CC
5
Cov
100%
get_factory
4.0
_load_all_builtins
2.0
BEGIN
1.0
CRAP 2.2
« blib/lib/SignalWire/Agents/Skills/Builtin/DatasphereServerless.pm ↑ Summary blib/lib/SignalWire/Agents/REST/Namespaces/Calling.pm »
1 package SignalWire::Agents::Skills::SkillRegistry;
2 # Copyright (c) 2025 SignalWire
3 # Licensed under the MIT License.
4  
5 19 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 19 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 # Global registry mapping skill name -> class name
9 19 my %REGISTRY;
10  
11 54 ▶sub register_skill {
Subroutine register_skill: called CC=1 SCAR=0.0
Pod undocumented
12 54 my ($class, $skill_name, $skill_class) = @_;
13 54 $REGISTRY{$skill_name} = $skill_class;
14 }
15  
16 185 ▶sub get_factory {
Subroutine get_factory: called CC=4 SCAR=13.9
Pod undocumented
17 185 my ($class, $skill_name) = @_;
18  
19 # Return if already registered
20 185 ▶ return $REGISTRY{$skill_name} if exists $REGISTRY{$skill_name};
Branch: 1 branch
BranchTrueFalseTotal
if exists $REGISTRY{$skill_name} 111 74 185
21  
22 # Attempt to auto-load from Builtin namespace
23 74 my $module = 'SignalWire::Agents::Skills::Builtin::' . _camelize($skill_name);
24 74 eval "require $module"; ## no critic
25 74 ▶ if (!$@) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($@) 71 3 74
26 # If the module registered itself, return it
27 71 ▶ return $REGISTRY{$skill_name} if exists $REGISTRY{$skill_name};
Branch: 1 branch
BranchTrueFalseTotal
if exists $REGISTRY{$skill_name} 53 18 71
28 # Otherwise register it
29 18 $REGISTRY{$skill_name} = $module;
30 18 return $module;
31 }
32  
33 3 return undef;
34 }
35  
36 5 ▶sub list_skills {
Subroutine list_skills: called CC=1 SCAR=0.0
Pod undocumented
37 5 my ($class) = @_;
38 # Make sure all builtins are loaded
39 5 $class->_load_all_builtins;
40 5 return [ sort keys %REGISTRY ];
41 }
42  
43 5 ▶sub _load_all_builtins {
Subroutine _load_all_builtins: called CC=2 SCAR=6.9
44 5 my ($class) = @_;
45 5 my @names = qw(
46 api_ninjas_trivia claude_skills datasphere datasphere_serverless
47 datetime google_maps info_gatherer joke math mcp_gateway
48 native_vector_search play_background_file spider swml_transfer
49 weather_api web_search wikipedia_search custom_skills
50 );
51 5 for my $name (@names) {
52 90 $class->get_factory($name); # triggers auto-load
53 }
54 }
55  
56 74 ▶sub _camelize {
Subroutine _camelize: called CC=1 SCAR=0.0
57 74 my ($name) = @_;
58 # Convert snake_case to CamelCase: api_ninjas_trivia -> ApiNinjasTrivia
59 74 $name =~ s/_(.)/uc($1)/ge;
60 74 return ucfirst($name);
61 }
62  
63 3 ▶sub clear_registry {
Subroutine clear_registry: called CC=1 SCAR=0.0
Pod undocumented
64 3 %REGISTRY = ();
65 }
66  
67 19 1;
« blib/lib/SignalWire/Agents/Skills/Builtin/DatasphereServerless.pm ↑ Summary blib/lib/SignalWire/Agents/REST/Namespaces/Calling.pm »