| 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
Condition66%2/3
defined $name and $name =~ /\A[A-Za-z0-9][A-Za-z0-9._-]*\z/
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/
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 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
Condition100%3/3
$at <= 0 or $at == length($entry) - 1
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
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 55 | 7 | my $prefix = substr $name, 0, $colon; | |||||||||||||||||||||||||||
| 56 | 7 | ▶ | if ( $prefix ne $type ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 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
Condition66%2/3
$at <= 0 or $at == length($entry) - 1
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
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 76 | 4 | my $prefix = substr $name, 0, $colon; | |||||||||||||||||||||||||||
| 77 | 4 | ▶ | if ( $prefix ne 'bundle' ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 83 | 11 | ▶ | if ( is_pattern($name) ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 95 | } | ||||||||||||||||||||||||||||
| 96 | |||||||||||||||||||||||||||||
| 97 | 39 | 1; | |||||||||||||||||||||||||||
| 98 | |||||||||||||||||||||||||||||
| 99 | __END__ | ||||||||||||||||||||||||||||