Conformance/Snapshot/Directory.pm

filter: Statementstmt 35.0% 27 / 77 Branchbran 0.0% 0 / 26 Conditioncond 0.0% 0 / 16 MC/DCmcdc 0.0% 0 / 9 Subroutinesub 40.9% 9 / 22 Podpod 100% 11 / 11 totaltotal 29.1% 47 / 161 CC 21 SCAR 22.9
CC
21
Cov
23%
__ANON__
20.0
install_hook
20.0
new
12.0
CRAP 9.9
« Conformance/Check/DataSchema.pm ↑ Summary Conformance/Check/ClaudeMd.pm »
1 package Dist::Conformance::Snapshot::Directory 0.006;
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 3 ▶use Dist::Conformance::Source::Git();
Subroutine BEGIN: called CC=1 SCAR=0.0
16  
17  
18 3 has 'root';
19  
20 # What git hashes: the target of a symbolic link, or the content of a file.
21 0 ▶my sub bytes_at ($name) {
Subroutine bytes_at: not called CC=2 SCAR=17.9
22 0 ▶ return readlink $name if -l $name;
Branch: 1 branch
BranchTrueFalseTotal
if -l $name 0 0 0
23 0 return Mojo::File->new($name)->slurp;
24 }
25  
26  
27 0 ▶sub new ( $class, @args ) {
Subroutine new: not called CC=3 SCAR=24.8
Pod documented
28 0 my $self = $class->SUPER::new(@args);
29 0 ▶ die "root is required\n" if !defined $self->root;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $self->root 0 0 0
30 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
31 0 $self->root( Mojo::File->new( $self->root ) );
32 0 return $self;
33 }
34  
35  
36 0 ▶sub file ( $self, $path ) {
Subroutine file: not called CC=1 SCAR=6.9
Pod documented
37 0 Dist::Conformance::Schema::relative_path( $path, 'the checkout' );
38 0 return $self->root->child( split m{/}, $path );
39 }
40  
41  
42 0 ▶sub paths ($self) {
Subroutine paths: not called CC=1 SCAR=6.9
Pod documented
43 0 my $root = $self->root;
44 0 my %paths;
45 File::Find::find(
46 {
47 no_chdir => 1,
48 0 ▶ wanted => sub {
Subroutine __ANON__: not called CC=4 SCAR=30.0
49 0 my $name = $File::Find::name;
50 0 ▶ if ( $_ =~ m{(?:\A|/)[.]git\z} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($_ =~ m[(?:\A|/)[.]git\z]aasx) 0 0 0
51 0 $File::Find::prune = 1;
52 0 return;
53 }
54 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
55 0 my $relative = Mojo::File->new($name)->to_rel($root)->to_string;
56 0 $paths{$relative} = Dist::Conformance::Snapshot::blob_sha( bytes_at($name) );
57 },
58 },
59 0 "$root",
60 );
61 0 return \%paths;
62 }
63  
64  
65 0 ▶sub contains ( $self, $path ) {
Subroutine contains: not called CC=3 SCAR=24.8
Pod documented
66 0 my $file = $self->file($path);
67 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
68 }
69  
70  
71 0 ▶sub sha ( $self, $path ) {
Subroutine sha: not called CC=2 SCAR=17.9
Pod documented
72 0 ▶ return undef if !$self->contains($path);
Branch: 1 branch
BranchTrueFalseTotal
unless $self->contains($path) 0 0 0
73 0 return Dist::Conformance::Snapshot::blob_sha( bytes_at( $self->file($path) ) );
74 }
75  
76  
77 0 ▶sub content ( $self, $path ) {
Subroutine content: not called CC=3 SCAR=24.8
Pod documented
78 0 my $file = $self->file($path);
79 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
80 0 return $file->slurp;
81 }
82  
83  
84 0 ▶sub writable ($) { return 1 }
Subroutine writable: not called CC=1 SCAR=6.9
Pod documented
85  
86  
87 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
88 0 my $file = $self->file($path);
89 0 $file->dirname->make_path;
90 0 File::Slurper::Temp::write_binary( "$file", $bytes );
91 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
92 0 return $file;
93 }
94  
95  
96 0 ▶sub hooks_dir ($self) {
Subroutine hooks_dir: not called CC=3 SCAR=24.8
Pod documented
97 0 my $root = $self->root;
98 0 ▶ return undef if !-e $root->child('.git');
Branch: 1 branch
BranchTrueFalseTotal
unless -e $root->child(".git") 0 0 0
99  
100 # The root decides, not a repository that the environment names.
101 0 delete local @ENV{qw{GIT_DIR GIT_WORK_TREE GIT_COMMON_DIR}};
102 0 chomp( my $path = Dist::Conformance::Source::Git::git( q{-C}, "$root", qw{rev-parse --git-path hooks} ) );
103 0 my $hooks = Mojo::File->new($path);
104  
105 # Mojo::File's to_abs resolves against the working directory, never a base.
106 0 ▶ return $hooks->is_abs ? $hooks : $root->child($path);
Branch: 1 branch
BranchTrueFalseTotal
$hooks->is_abs ? : 0 0 0
107 }
108  
109  
110 0 ▶sub installed_hook ( $self, $name ) {
Subroutine installed_hook: not called CC=3 SCAR=24.8
Pod documented
111 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
112 0 my $hook = $dir->child($name);
113 0 ▶ return -e $hook ? $hook->slurp : undef;
Branch: 1 branch
BranchTrueFalseTotal
-e $hook ? : 0 0 0
114 }
115  
116  
117 0 ▶sub install_hook ( $self, $name, $bytes ) {
Subroutine install_hook: not called CC=4 SCAR=30.0
Pod documented
118 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
119 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
120 0 $dir->make_path;
121 0 my $hook = $dir->child($name);
122 0 File::Slurper::Temp::write_binary( "$hook", $bytes );
123 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
124 0 return $hook;
125 }
126  
127 __END__
« Conformance/Check/DataSchema.pm ↑ Summary Conformance/Check/ClaudeMd.pm »