Conformance/Snapshot/Directory.pm

filter: Statementstmt 30.0% 24 / 80 Branchbran 0.0% 0 / 32 Conditioncond 0.0% 0 / 16 MC/DCmcdc 0.0% 0 / 9 Subroutinesub 36.3% 8 / 22 Podpod 100% 11 / 11 totaltotal 25.2% 43 / 170 CC 24 SCAR 24.8
CC
24
Cov
19%
hooks_dir
30.0
__ANON__
20.0
install_hook
20.0
CRAP 12.0
« Conformance/Check/ClaudeSettings.pm ↑ Summary Conformance/Source/Git.pm »
1 package Dist::Conformance::Snapshot::Directory 0.004;
2  
3 # ABSTRACT: A snapshot of a checkout on this machine, which an update can change
4  
5 3 ▶use 5.040;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 3 ▶use warnings FATAL => 'all';
Subroutine BEGIN: called CC=1 SCAR=0.0
7 3 ▶use re '/aasx';
Subroutine BEGIN: called CC=1 SCAR=0.0
8 3 ▶use Mojo::Base 'Dist::Conformance::Snapshot', -signatures;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 3 ▶use File::Find();
Subroutine BEGIN: called CC=1 SCAR=0.0
11 3 ▶use File::Slurper::Temp();
Subroutine BEGIN: called CC=1 SCAR=0.0
12 3 ▶use Mojo::File();
Subroutine BEGIN: called CC=1 SCAR=0.0
13  
14 3 ▶use Dist::Conformance::Schema();
Subroutine BEGIN: called CC=1 SCAR=0.0
15  
16  
17 3 has 'root';
18  
19 # What git hashes: the target of a symbolic link, or the content of a file.
20 0 ▶my sub bytes_at ($name) {
Subroutine bytes_at: not called CC=2 SCAR=17.9
21 0 ▶ return readlink $name if -l $name;
Branch: 1 branch
BranchTrueFalseTotal
if -l $name 0 0 0
22 0 return Mojo::File->new($name)->slurp;
23 }
24  
25 # Mojo::File's to_abs resolves against the working directory, never a base.
26 0 ▶my sub relative_to ( $path, $base ) {
Subroutine relative_to: not called CC=2 SCAR=17.9
27 0 my $file = Mojo::File->new($path);
28 0 ▶ return $file->is_abs ? $file : $base->child($path);
Branch: 1 branch
BranchTrueFalseTotal
$file->is_abs ? : 0 0 0
29 }
30  
31  
32 0 ▶sub new ( $class, @args ) {
Subroutine new: not called CC=3 SCAR=24.8
Pod documented
33 0 my $self = $class->SUPER::new(@args);
34 0 ▶ die "root is required\n" if !defined $self->root;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $self->root 0 0 0
35 0 ▶ die( 'root ' . $self->root . " is not a directory\n" ) if !-d $self->root;
Branch: 1 branch
BranchTrueFalseTotal
unless -d $self->root 0 0 0
36 0 $self->root( Mojo::File->new( $self->root ) );
37 0 return $self;
38 }
39  
40  
41 0 ▶sub file ( $self, $path ) {
Subroutine file: not called CC=1 SCAR=6.9
Pod documented
42 0 Dist::Conformance::Schema::relative_path( $path, 'the checkout' );
43 0 return $self->root->child( split m{/}, $path );
44 }
45  
46  
47 0 ▶sub paths ($self) {
Subroutine paths: not called CC=1 SCAR=6.9
Pod documented
48 0 my $root = $self->root;
49 0 my %paths;
50 File::Find::find(
51 {
52 no_chdir => 1,
53 0 ▶ wanted => sub {
Subroutine __ANON__: not called CC=4 SCAR=30.0
54 0 my $name = $File::Find::name;
55 0 ▶ if ( $_ =~ m{(?:\A|/)[.]git\z} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($_ =~ m[(?:\A|/)[.]git\z]aasx) 0 0 0
56 0 $File::Find::prune = 1;
57 0 return;
58 }
59 0 ▶ return if !-l $name && -d _;
Branch: 1 branch
BranchTrueFalseTotal
if not -l $name and -d _ 0 0 0
Condition0%0/3
not -l $name and -d _
!ll&&!rl&&r
000
MC/DC0%0/2
not -l $name and -d _
not -l $name -d _
Truth table0%0/3
not(A) and B
A= not -l $nameB= -d _
ABresult
0X0
100
111
60 0 my $relative = Mojo::File->new($name)->to_rel($root)->to_string;
61 0 $paths{$relative} = Dist::Conformance::Snapshot::blob_sha( bytes_at($name) );
62 },
63 },
64 0 "$root",
65 );
66 0 return \%paths;
67 }
68  
69  
70 0 ▶sub contains ( $self, $path ) {
Subroutine contains: not called CC=3 SCAR=24.8
Pod documented
71 0 my $file = $self->file($path);
72 0 ▶ return -l $file || ( -e _ && !-d _ );
Condition0%0/6
-l $file || -e _ && !-d(_)
l!l&&r!l&&!r
000
-e _ and not -d _
!ll&&!rl&&r
000
MC/DC0%0/3
-l $file || -e _ && !-d(_)
-l $file -e _ not -d _
Truth table0%0/4
A || B and not(C)
A= -l $fileB= -e _C= not -d _
ABCresult
1XX1
0111
00X0
0100
73 }
74  
75  
76 0 ▶sub sha ( $self, $path ) {
Subroutine sha: not called CC=2 SCAR=17.9
Pod documented
77 0 ▶ return undef if !$self->contains($path);
Branch: 1 branch
BranchTrueFalseTotal
unless $self->contains($path) 0 0 0
78 0 return Dist::Conformance::Snapshot::blob_sha( bytes_at( $self->file($path) ) );
79 }
80  
81  
82 0 ▶sub content ( $self, $path ) {
Subroutine content: not called CC=3 SCAR=24.8
Pod documented
83 0 my $file = $self->file($path);
84 0 ▶ return undef if !-e $file || -d _;
Branch: 1 branch
BranchTrueFalseTotal
if not -e $file or -d _ 0 0 0
Condition0%0/3
not -e $file or -d _
l!l&&r!l&&!r
000
MC/DC0%0/2
not -e $file or -d _
not -e $file -d _
Truth table0%0/3
not(A) or B
A= not -e $fileB= -d _
ABresult
1X1
011
000
85 0 return $file->slurp;
86 }
87  
88  
89 0 ▶sub writable ($) { return 1 }
Subroutine writable: not called CC=1 SCAR=6.9
Pod documented
90  
91  
92 0 ▶sub write ( $self, $path, $bytes, $mode = oct 644 ) { ## no critic (Subroutines::ProhibitBuiltinHomonyms) -- the method of a writable snapshot, never called as the builtin
Subroutine write: not called CC=3 SCAR=24.8
Pod documented
93 0 my $file = $self->file($path);
94 0 $file->dirname->make_path;
95 0 File::Slurper::Temp::write_binary( "$file", $bytes );
96 0 ▶ chmod $mode, "$file" or die("Cannot chmod $file: $!\n");
Branch: 1 branch
BranchTrueFalseTotal
chmod $mode, "$file" or die "Cannot chmod ${file}: $!\n" 0 0 0
97 0 return $file;
98 }
99  
100  
101 0 ▶sub hooks_dir ($self) {
Subroutine hooks_dir: not called CC=5 SCAR=34.0
Pod documented
102 0 my $dot_git = $self->root->child('.git');
103 0 ▶ return $dot_git->child('hooks') if -d $dot_git;
Branch: 1 branch
BranchTrueFalseTotal
if -d $dot_git 0 0 0
104 0 ▶ return undef if !-e $dot_git;
Branch: 1 branch
BranchTrueFalseTotal
unless -e $dot_git 0 0 0
105 0 my ($gitdir) = $dot_git->slurp =~ m{\Agitdir:\ *(.+?)\s*\z};
106 0 ▶ return undef if !defined $gitdir;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $gitdir 0 0 0
107 0 $gitdir = relative_to( $gitdir, $self->root );
108 0 my $common = $gitdir->child('commondir');
109 0 ▶ return $gitdir->child('hooks') if !-e $common;
Branch: 1 branch
BranchTrueFalseTotal
unless -e $common 0 0 0
110 0 ( my $relative = $common->slurp ) =~ s/\s+\z//;
111 0 return relative_to( $relative, $gitdir )->child('hooks');
112 }
113  
114  
115 0 ▶sub installed_hook ( $self, $name ) {
Subroutine installed_hook: not called CC=3 SCAR=24.8
Pod documented
116 0 ▶ my $dir = $self->hooks_dir // return undef;
Condition0%0/2
$self->hooks_dir // (return undef)
l!l
00
MC/DC0%0/1
$self->hooks_dir // (return undef)
$self->hooks_dir
Truth table0%0/2
A
A= $self->hooks_dir
Aresult
11
00
117 0 my $hook = $dir->child($name);
118 0 ▶ return -e $hook ? $hook->slurp : undef;
Branch: 1 branch
BranchTrueFalseTotal
-e $hook ? : 0 0 0
119 }
120  
121  
122 0 ▶sub install_hook ( $self, $name, $bytes ) {
Subroutine install_hook: not called CC=4 SCAR=30.0
Pod documented
123 0 ▶ die "$name is not a hook name\n" if $name !~ m{\A[[:lower:]][[:lower:]-]*\z};
Branch: 1 branch
BranchTrueFalseTotal
unless $name =~ /\A[[:lower:]][[:lower:]-]*\z/aasx 0 0 0
124 0 ▶ my $dir = $self->hooks_dir // die( $self->root . " is not a git checkout\n" );
Condition0%0/2
$self->hooks_dir // die($self->root . " is not a git checkout\n")
l!l
00
MC/DC0%0/1
$self->hooks_dir // die($self->root . " is not a git checkout\n")
$self->hooks_dir
Truth table0%0/2
A
A= $self->hooks_dir
Aresult
11
00
125 0 $dir->make_path;
126 0 my $hook = $dir->child($name);
127 0 File::Slurper::Temp::write_binary( "$hook", $bytes );
128 0 ▶ chmod oct 755, "$hook" or die("Cannot chmod $hook: $!\n");
Branch: 1 branch
BranchTrueFalseTotal
chmod 0755, "$hook" or die "Cannot chmod ${hook}: $!\n" 0 0 0
129 0 return $hook;
130 }
131  
132 __END__
« Conformance/Check/ClaudeSettings.pm ↑ Summary Conformance/Source/Git.pm »