| 1 | package Skilletor::Cache; | ||||||||||||||||||||||||||||
| 2 | # ABSTRACT: Where a git or url source is cached – the reference's cache naming | ||||||||||||||||||||||||||||
| 3 | |||||||||||||||||||||||||||||
| 4 | 236 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | 236 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||
| 7 | 236 | ▶ | use Digest::SHA qw( sha256_hex ); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | 236 | ▶ | use Exporter qw( import ); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 9 | 236 | ▶ | use Skilletor::FSUtil qw( encode_text path_join ); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 10 | 236 | ▶ | use Skilletor::JSON qw( js_stringify ); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||
| 12 | 236 | our $VERSION = '0.001'; | |||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||
| 14 | 236 | our @EXPORT_OK = qw( cache_root cache_name git_identity git_cache_dir url_cache_dir CACHE_NAME_RE ); | |||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||
| 16 | # The name a cache dir has: 16 hex digits of a sha256 (git and url caches share the scheme). | ||||||||||||||||||||||||||||
| 17 | 236 | ▶ | use constant CACHE_NAME_RE => qr/\A[0-9a-f]{16}\z/; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||
| 19 | 1 | ▶ | sub cache_root { | ||||||||||||||||||||||||||
|
Subroutine
cache_root: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 20 | 1 | my ( $home ) = @_; | |||||||||||||||||||||||||||
| 21 | 1 | return path_join( $home, '.claude', 'skilletor', 'cache' ); | |||||||||||||||||||||||||||
| 22 | } | ||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||
| 24 | 4047 | ▶ | sub cache_name { | ||||||||||||||||||||||||||
|
Subroutine
cache_name: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 25 | 4047 | my ( $identity ) = @_; | |||||||||||||||||||||||||||
| 26 | 4047 | return substr( sha256_hex( encode_text($identity) ), 0, 16 ); | |||||||||||||||||||||||||||
| 27 | } | ||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||
| 29 | # An unpinned source keeps the legacy URL-only identity; an explicit ref never shares it. | ||||||||||||||||||||||||||||
| 30 | 4025 | ▶ | sub git_identity { | ||||||||||||||||||||||||||
|
Subroutine
git_identity: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||
| 31 | 4025 | my ( $url, $ref ) = @_; | |||||||||||||||||||||||||||
| 32 | 4025 | ▶ | return ( defined $ref && length $ref ) ? js_stringify( [ $url, $ref ] ) : $url; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
defined $ref and length $ref
MC/DC100%2/2
defined $ref and length $ref
defined $ref
length $ref
Truth table100%3/3
A and B
A= defined $refB= length $ref
| |||||||||||||||||||||||||||||
| 33 | } | ||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||
| 35 | 3906 | ▶ | sub git_cache_dir { | ||||||||||||||||||||||||||
|
Subroutine
git_cache_dir: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 36 | 3906 | my ( $root, $url, $ref ) = @_; | |||||||||||||||||||||||||||
| 37 | 3906 | return path_join( $root, cache_name( git_identity( $url, $ref ) ) ); | |||||||||||||||||||||||||||
| 38 | } | ||||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||
| 40 | 23 | ▶ | sub url_cache_dir { | ||||||||||||||||||||||||||
|
Subroutine
url_cache_dir: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 41 | 23 | my ( $root, $url ) = @_; | |||||||||||||||||||||||||||
| 42 | 23 | return path_join( $root, cache_name($url) ); | |||||||||||||||||||||||||||
| 43 | } | ||||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||
| 45 | 236 | 1; | |||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||
| 47 | __END__ | ||||||||||||||||||||||||||||