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
« Skilletor/Render.pm ↑ Summary Skilletor/Source/Local.pm »
1 package Skilletor::Entry;
2 # ABSTRACT: Install entries ([type:]name@source, patterns, bundles) and the names they hold
3  
4 39 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 39 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 39 ▶use Exporter qw( import );
Subroutine BEGIN: called CC=1 SCAR=0.0
8 39 ▶use Skilletor::Error::Config;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 39 ▶use Skilletor::JSString qw( js_lc );
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 39 our $VERSION = '0.001';
12  
13 39 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 39 ▶use constant ITEM_TYPES => qw( skill agent rule );
Subroutine BEGIN: called CC=1 SCAR=0.0
20 39 ▶use constant HARNESSES => qw( claude codex hermes );
Subroutine BEGIN: called CC=1 SCAR=0.0
21 39 ▶use constant WILDCARD => '*';
Subroutine BEGIN: called CC=1 SCAR=0.0
22 39 ▶use constant BUNDLES_KEY => 'bundles';
Subroutine BEGIN: called CC=1 SCAR=0.0
23 39 ▶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 39 ▶use constant INSTALL_KEYS => ( skills => 'skill', agents => 'agent', rules => 'rule' );
Subroutine BEGIN: called CC=1 SCAR=0.0
27 39 ▶use constant INSTALL_KEY_OF => { skill => 'skills', agent => 'agents', rule => 'rules' };
Subroutine BEGIN: called CC=1 SCAR=0.0
28  
29 6555 ▶sub name_key {
Subroutine name_key: called CC=1 SCAR=0.0
Pod documented
30 6555 my ( $name ) = @_;
31 6555 return js_lc($name);
32 }
33  
34 986 ▶sub is_source_name {
Subroutine is_source_name: called CC=3 SCAR=11.1
Pod documented
35 986 my ( $name ) = @_;
36 986 ▶ 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/ ? : 964 22 986
Condition66%2/3
defined $name and $name =~ /\A[A-Za-z0-9][A-Za-z0-9._-]*\z/
!ll&&!rl&&r
022964
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 3010 ▶sub is_pattern {
Subroutine is_pattern: called CC=2 SCAR=6.9
Pod documented
40 3010 my ( $name ) = @_;
41 3010 ▶ return index( $name, WILDCARD ) >= 0 ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
index($name, '*') != -1 ? : 228 2782 3010
42 }
43  
44 # `[type:]name@source` under one type's list. The list's type wins; a prefix must match it.
45 1252 ▶sub parse_entry {
Subroutine parse_entry: called CC=6 SCAR=17.9
Pod documented
46 1252 my ( $entry, $type, $path, $where ) = @_;
47 1252 my $at = rindex $entry, '@';
48 1252 ▶ if ( $at <= 0 || $at == length($entry) - 1 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($at <= 0 or $at == length($entry) - 1) 3 1249 1252
Condition100%3/3
$at <= 0 or $at == length($entry) - 1
l!l&&r!l&&!r
211249
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 1249 my $source = substr $entry, $at + 1;
52 1249 my $name = substr $entry, 0, $at;
53 1249 my $colon = index $name, ':';
54 1249 ▶ if ( $colon != -1 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($colon != -1) 7 1242 1249
55 7 my $prefix = substr $name, 0, $colon;
56 7 ▶ if ( $prefix ne $type ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($prefix ne $type) 2 5 7
57 2 Skilletor::Error::Config->throw(
58 $path.': '.$where.' "'.$entry.'" declares type "'.$prefix.'" but is under '.$type.'s' );
59 }
60 5 $name = substr $name, $colon + 1;
61 }
62 1247 ▶ Skilletor::Error::Config->throw( $path.': '.$where.' "'.$entry.'" has an empty name' ) unless length $name;
Branch: 1 branch
BranchTrueFalseTotal
unless length $name 1 1246 1247
63 1246 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 14 ▶sub parse_bundle_entry {
Subroutine parse_bundle_entry: called CC=7 SCAR=19.5
Pod documented
68 14 my ( $entry, $path, $where ) = @_;
69 14 my $at = rindex $entry, '@';
70 14 ▶ if ( $at <= 0 || $at == length($entry) - 1 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($at <= 0 or $at == length($entry) - 1) 1 13 14
Condition66%2/3
$at <= 0 or $at == length($entry) - 1
l!l&&r!l&&!r
1013
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 13 my $name = substr $entry, 0, $at;
74 13 my $colon = index $name, ':';
75 13 ▶ if ( $colon != -1 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($colon != -1) 4 9 13
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 12 ▶ Skilletor::Error::Config->throw( $path.': '.$where.' "'.$entry.'" has an empty name' ) unless length $name;
Branch: 1 branch
BranchTrueFalseTotal
unless length $name 1 11 12
83 11 ▶ if ( is_pattern($name) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (is_pattern($name)) 1 10 11
84 1 Skilletor::Error::Config->throw( $path.': '.$where.' "'.$entry.'": patterns over bundle names are not supported' );
85 }
86 10 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 1733 ▶sub seen_key {
Subroutine seen_key: called CC=2 SCAR=6.9
Pod documented
91 1733 my ( $item ) = @_;
92 return is_pattern( $item->{name} )
93 ? $item->{type}.'/'.$item->{name}.'@'.$item->{source}
94 1733 ▶ : $item->{type}.'/'.name_key( $item->{name} );
Branch: 1 branch
BranchTrueFalseTotal
is_pattern($item->{'name'}) ? : 114 1619 1733
95 }
96  
97 39 1;
98  
99 __END__
« Skilletor/Render.pm ↑ Summary Skilletor/Source/Local.pm »