lib/Skilletor/Entry.pm

filter: Statementstmt 100% 76 / 76 Branchbran 100% 24 / 24 Conditioncond 77.7% 7 / 9 MC/DCmcdc 66.6% 4 / 6 Subroutinesub 100% 18 / 18 Podpod 100% 6 / 6 totaltotal 97.1% 135 / 139 CC 16 SCAR 12.5
CC
16
Cov
98%
parse_bundle_entry
7.0
parse_entry
6.0
is_source_name
3.0
CRAP 3.5
« lib/Skilletor/Backend.pm ↑ Summary /usr/local/lib/perl5/5.44.0/x86_64-linux/Encode/Encoding.pm »
1 package Skilletor::Entry;
2 # ABSTRACT: Install entries ([type:]name@source, patterns, bundles) and the names they hold
3  
4 415 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 415 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 415 ▶use Exporter qw( import );
Subroutine BEGIN: called CC=1 SCAR=0.0
8 415 ▶use Skilletor::Error::Config;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 415 ▶use Skilletor::JSString qw( js_lc );
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 415 our $VERSION = '0.008000';
12  
13 415 our @EXPORT_OK = qw(
14 ITEM_TYPES HARNESSES WILDCARD SOURCE_NAME_RULE INSTALL_KEYS INSTALL_KEY_OF BUNDLES_KEY
15 name_key is_source_name is_pattern
16 parse_entry parse_bundle_entry seen_key
17 );
18  
19 415 ▶use constant ITEM_TYPES => qw( skill agent rule );
Subroutine BEGIN: called CC=1 SCAR=0.0
20 415 ▶use constant HARNESSES => qw( claude codex hermes );
Subroutine BEGIN: called CC=1 SCAR=0.0
21 415 ▶use constant WILDCARD => '*';
Subroutine BEGIN: called CC=1 SCAR=0.0
22 415 ▶use constant BUNDLES_KEY => 'bundles';
Subroutine BEGIN: called CC=1 SCAR=0.0
23 415 ▶use constant SOURCE_NAME_RULE => 'ASCII letters, digits, ".", "_" and "-", starting with a letter or digit';
Subroutine BEGIN: called CC=1 SCAR=0.0
24  
25 # Config install keys and their item types, in the reference's order.
26 415 ▶use constant INSTALL_KEYS => ( skills => 'skill', agents => 'agent', rules => 'rule' );
Subroutine BEGIN: called CC=1 SCAR=0.0
27 415 ▶use constant INSTALL_KEY_OF => { skill => 'skills', agent => 'agents', rule => 'rules' };
Subroutine BEGIN: called CC=1 SCAR=0.0
28  
29 36583 ▶sub name_key {
Subroutine name_key: called CC=1 SCAR=0.0
Pod documented
30 36583 my ( $name ) = @_;
31 36583 return js_lc($name);
32 }
33  
34 12128 ▶sub is_source_name {
Subroutine is_source_name: called CC=3 SCAR=11.1
Pod documented
35 12128 my ( $name ) = @_;
36 12128 ▶ return ( defined $name && $name =~ /\A[A-Za-z0-9][A-Za-z0-9._-]*\z/ ) ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
defined $name && $name =~ /\A[A-Za-z0-9][A-Za-z0-9._-]*\z/ ? : 12037 91 12128
Condition66%2/3
defined $name and $name =~ /\A[A-Za-z0-9][A-Za-z0-9._-]*\z/
!ll&&!rl&&r
09112037
MC/DC50%1/2
defined $name and $name =~ /\A[A-Za-z0-9][A-Za-z0-9._-]*\z/
defined $name $name =~ /\A[A-Za-z0-9][A-Za-z0-9._-]*\z/
Truth table66%2/3
A and B
A= defined $nameB= $name =~ /\A[A-Za-z0-9][A-Za-z0-9._-]*\z/
ABresult
0X0
100
111
37 }
38  
39 32334 ▶sub is_pattern {
Subroutine is_pattern: called CC=2 SCAR=6.9
Pod documented
40 32334 my ( $name ) = @_;
41 32334 ▶ return index( $name, WILDCARD ) >= 0 ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
index($name, '*') != -1 ? : 440 31894 32334
42 }
43  
44 # `[type:]name@source` under one type's list. The list's type wins; a prefix must match it.
45 13127 ▶sub parse_entry {
Subroutine parse_entry: called CC=6 SCAR=17.9
Pod documented
46 13127 my ( $entry, $type, $path, $where ) = @_;
47 13127 my $at = rindex $entry, '@';
48 13127 ▶ if ( $at <= 0 || $at == length($entry) - 1 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($at <= 0 or $at == length($entry) - 1) 3 13124 13127
Condition100%3/3
$at <= 0 or $at == length($entry) - 1
l!l&&r!l&&!r
2113124
MC/DC100%2/2
$at <= 0 or $at == length($entry) - 1
$at <= 0 $at == length($entry) - 1
Truth table100%3/3
A or B
A= $at <= 0B= $at == length($entry) - 1
ABresult
1X1
011
000
49 3 Skilletor::Error::Config->throw( $path.': '.$where.' "'.$entry.'" must be name@source' );
50 }
51 13124 my $source = substr $entry, $at + 1;
52 13124 my $name = substr $entry, 0, $at;
53 13124 my $colon = index $name, ':';
54 13124 ▶ if ( $colon != -1 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($colon != -1) 13 13111 13124
55 13 my $prefix = substr $name, 0, $colon;
56 13 ▶ if ( $prefix ne $type ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($prefix ne $type) 2 11 13
57 2 Skilletor::Error::Config->throw(
58 $path.': '.$where.' "'.$entry.'" declares type "'.$prefix.'" but is under '.$type.'s' );
59 }
60 11 $name = substr $name, $colon + 1;
61 }
62 13122 ▶ Skilletor::Error::Config->throw( $path.': '.$where.' "'.$entry.'" has an empty name' ) unless length $name;
Branch: 1 branch
BranchTrueFalseTotal
unless length $name 1 13121 13122
63 13121 return { type => $type, name => $name, source => $source, target => $type.'s/'.$name, raw => $entry };
64 }
65  
66 # `[bundle:]name@source` under install.bundles; no patterns.
67 406 ▶sub parse_bundle_entry {
Subroutine parse_bundle_entry: called CC=7 SCAR=19.5
Pod documented
68 406 my ( $entry, $path, $where ) = @_;
69 406 my $at = rindex $entry, '@';
70 406 ▶ if ( $at <= 0 || $at == length($entry) - 1 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($at <= 0 or $at == length($entry) - 1) 1 405 406
Condition66%2/3
$at <= 0 or $at == length($entry) - 1
l!l&&r!l&&!r
10405
MC/DC50%1/2
$at <= 0 or $at == length($entry) - 1
$at <= 0 $at == length($entry) - 1
Truth table66%2/3
A or B
A= $at <= 0B= $at == length($entry) - 1
ABresult
1X1
011
000
71 1 Skilletor::Error::Config->throw( $path.': '.$where.' "'.$entry.'" must be name@source' );
72 }
73 405 my $name = substr $entry, 0, $at;
74 405 my $colon = index $name, ':';
75 405 ▶ if ( $colon != -1 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($colon != -1) 4 401 405
76 4 my $prefix = substr $name, 0, $colon;
77 4 ▶ if ( $prefix ne 'bundle' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($prefix ne "bundle") 1 3 4
78 1 Skilletor::Error::Config->throw( $path.': '.$where.' "'.$entry.'" declares type "'.$prefix.'" but is under bundles' );
79 }
80 3 $name = substr $name, $colon + 1;
81 }
82 404 ▶ Skilletor::Error::Config->throw( $path.': '.$where.' "'.$entry.'" has an empty name' ) unless length $name;
Branch: 1 branch
BranchTrueFalseTotal
unless length $name 1 403 404
83 403 ▶ if ( is_pattern($name) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (is_pattern($name)) 1 402 403
84 1 Skilletor::Error::Config->throw( $path.': '.$where.' "'.$entry.'": patterns over bundle names are not supported' );
85 }
86 402 return { name => $name, source => substr( $entry, $at + 1 ), raw => $entry };
87 }
88  
89 # The duplicate key of an entry: a name per type, ignoring case; a pattern per type and source.
90 18624 ▶sub seen_key {
Subroutine seen_key: called CC=2 SCAR=6.9
Pod documented
91 18624 my ( $item ) = @_;
92 return is_pattern( $item->{name} )
93 ? $item->{type}.'/'.$item->{name}.'@'.$item->{source}
94 18624 ▶ : $item->{type}.'/'.name_key( $item->{name} );
Branch: 1 branch
BranchTrueFalseTotal
is_pattern($item->{'name'}) ? : 204 18420 18624
95 }
96  
97 415 1;
98  
99 __END__
« lib/Skilletor/Backend.pm ↑ Summary /usr/local/lib/perl5/5.44.0/x86_64-linux/Encode/Encoding.pm »