Skilletor/Cache.pm

filter: Statementstmt 100% 34 / 34 Branchbran 100% 2 / 2 Conditioncond 100% 3 / 3 MC/DCmcdc 100% 2 / 2 Subroutinesub 100% 12 / 12 Podpod 100% 5 / 5 totaltotal 100% 58 / 58 CC 3 SCAR 3.6
CC
3
Cov
100%
git_identity
3.0
BEGIN
1.0
BEGIN
1.0
CRAP 1.4
« Skilletor/Error.pm ↑ Summary Skilletor/Error/Ambiguous.pm »
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
BranchTrueFalseTotal
defined $ref && length $ref ? : 1800 2225 4025
Condition100%3/3
defined $ref and length $ref
!ll&&!rl&&r
222411800
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
ABresult
0X0
100
111
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__
« Skilletor/Error.pm ↑ Summary Skilletor/Error/Ambiguous.pm »