blib/lib/DBIO/Skills.pm

filter: Statementstmt 72.8% 43 / 59 Branchbran 45.0% 9 / 20 Conditioncond 0.0% 0 / 6 MC/DCmcdc 0.0% 0 / 4 Subroutinesub 66.6% 8 / 12 Podpod 100% 5 / 5 totaltotal 61.3% 65 / 106 CC 18 SCAR 18.9
CC
18
Cov
61%
register_dist
12.0
register_class
12.0
skills
12.0
CRAP 6.6
« blib/lib/DBIO/Candy.pm ↑ Summary blib/lib/DBIO/DeploymentHandler/VersionStorage/Standard/VersionResult.pm »
1 package DBIO::Skills;
2 # ABSTRACT: Runtime access to the AI agent skills bundled with DBIO
3  
4 374 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 374 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 374 our $VERSION = '0.900007';
8  
9 374 ▶use File::ShareDir ();
Subroutine BEGIN: called CC=1 SCAR=0.0
10 374 ▶use File::Spec;
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12  
13 # dist name => { skill-dir-name => path to SKILL.md } (lazy, cached)
14 374 my %_skills_cache;
15 # dist names known to be loaded (the core dist is always present)
16 374 my %_loaded_dist = ( 'DBIO' => 1 );
17  
18  
19 0 ▶sub register_dist {
Subroutine register_dist: not called CC=3 SCAR=24.8
Pod documented
20 0 my ($class, $dist) = @_;
21 0 ▶ $_loaded_dist{$dist} = 1 if defined $dist && length $dist;
Branch: 1 branch
BranchTrueFalseTotal
if defined $dist and length $dist 0 0 0
Condition0%0/3
defined $dist and length $dist
!ll&&!rl&&r
000
MC/DC0%0/2
defined $dist and length $dist
defined $dist length $dist
Truth table0%0/3
A and B
A= defined $distB= length $dist
ABresult
0X0
100
111
22 0 return;
23 }
24  
25  
26 0 ▶sub register_class {
Subroutine register_class: not called CC=3 SCAR=24.8
Pod documented
27 0 my ($class, $pkg) = @_;
28 0 ▶ return unless defined $pkg && $pkg =~ /^(DBIO)::([^:]+)::/;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $pkg and $pkg =~ /^(DBIO)::([^:]+)::/ 0 0 0
Condition0%0/3
defined $pkg and $pkg =~ /^(DBIO)::([^:]+)::/
!ll&&!rl&&r
000
MC/DC0%0/2
defined $pkg and $pkg =~ /^(DBIO)::([^:]+)::/
defined $pkg $pkg =~ /^(DBIO)::([^:]+)::/
Truth table0%0/3
A and B
A= defined $pkgB= $pkg =~ /^(DBIO)::([^:]+)::/
ABresult
0X0
100
111
29 0 return $class->register_dist("$1-$2");
30 }
31  
32 # Resolve a dist's sharedir skills: { name => SKILL.md path }. Cached; missing
33 # sharedir (e.g. running uninstalled) yields an empty map rather than dying.
34 2 ▶sub _scan_dist {
Subroutine _scan_dist: called CC=6 SCAR=18.0
35 2 my ($dist) = @_;
36 2 ▶ return $_skills_cache{$dist} if exists $_skills_cache{$dist};
Branch: 1 branch
BranchTrueFalseTotal
if exists $_skills_cache{$dist} 1 1 2
37  
38 1 my %map;
39 1 my $dir = eval { File::ShareDir::dist_dir($dist) };
40 1 ▶ if (defined $dir) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $dir) 1 0 1
41 1 my $sdir = File::Spec->catdir($dir, 'skills');
42 1 ▶ if (opendir my $dh, $sdir) {
Branch: 1 branch
BranchTrueFalseTotal
if (opendir my $dh, $sdir) 1 0 1
43 1 for my $name (grep { !/^\./ } readdir $dh) {
44 10 my $file = File::Spec->catfile($sdir, $name, 'SKILL.md');
45 10 ▶ $map{$name} = $file if -f $file;
Branch: 1 branch
BranchTrueFalseTotal
if -f $file 10 0 10
46 }
47 1 closedir $dh;
48 }
49 }
50  
51 1 $_skills_cache{$dist} = \%map;
52 1 return \%map;
53 }
54  
55 # Canonical skill name is always the dbio- form (matches the sharedir dir
56 # names). A bare name gets dbio- prepended; an already-prefixed name is left
57 # as-is. So both 'db2-database' and 'dbio-db2-database' resolve.
58 16 ▶sub _canonical { my $n = shift; return $n =~ /^dbio-/ ? $n : "dbio-$n"; }
Subroutine _canonical: called CC=2 SCAR=6.9
Branch: 1 branch
BranchTrueFalseTotal
$n =~ /^dbio-/ ? : 1 15 16
59  
60  
61 14 ▶sub canonical_name { my ($class, $name) = @_; return _canonical($name); }
Subroutine canonical_name: called CC=1 SCAR=0.0
Pod documented
62  
63 0 ▶sub _slurp {
Subroutine _slurp: not called CC=2 SCAR=17.9
64 0 my ($file) = @_;
65 0 ▶ open my $fh, '<:encoding(UTF-8)', $file or return undef;
Branch: 1 branch
BranchTrueFalseTotal
open my $fh, "<:encoding(UTF-8)", $file or return undef 0 0 0
66 0 local $/;
67 0 return scalar <$fh>;
68 }
69  
70  
71 2 ▶sub skill {
Subroutine skill: called CC=5 SCAR=16.3
Pod documented
72 2 my ($class, $name) = @_;
73 2 ▶ return undef unless defined $name;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $name 0 2 2
74 2 my $want = _canonical($name);
75  
76 2 for my $dist (sort keys %_loaded_dist) {
77 2 my $map = _scan_dist($dist);
78 # Sharedir dir names are canonical (dbio-...) for the skills the family
79 # ships; a dist may still carry one under another name, so try the
80 # canonical form first, then the literal name as given.
81 2 for my $key ($want, $name) {
82 4 ▶ return _slurp($map->{$key}) if $map->{$key};
Branch: 1 branch
BranchTrueFalseTotal
if $map->{$key} 0 4 4
83 }
84 }
85 2 return undef;
86 }
87  
88  
89 0 ▶sub skills {
Subroutine skills: not called CC=3 SCAR=24.8
Pod documented
90 0 my ($class) = @_;
91 0 my %seen;
92 0 for my $dist (keys %_loaded_dist) {
93 0 $seen{$_} = 1 for keys %{ _scan_dist($dist) };
94 }
95 0 return sort keys %seen;
96 }
97  
98 374 1;
99  
100 __END__
« blib/lib/DBIO/Candy.pm ↑ Summary blib/lib/DBIO/DeploymentHandler/VersionStorage/Standard/VersionResult.pm »