| 1 | package Dist::Conformance::Snapshot 0.011; | ||
| 2 | |||
| 3 | # ABSTRACT: What a check can read of a repository: its paths, their blob SHAs and their contents | ||
| 4 | |||
| 5 | 6 | ▶ | use 5.040; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 6 | 6 | ▶ | use warnings FATAL => 'all'; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 7 | 6 | ▶ | use re '/aasx'; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 8 | 6 | ▶ | use Mojo::Base -base, -signatures; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 9 | |||
| 10 | 6 | ▶ | use Digest::SHA(); |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 11 | |||
| 12 | |||
| 13 | # Every path of the snapshot, with its git blob SHA. A subclass must implement | ||
| 14 | # it. | ||
| 15 | # @returns HashRef from each path to its git blob SHA, in lowercase hex | ||
| 16 | # @throws when the subclass does not implement it | ||
| 17 | # @example my $paths = $snapshot->paths; | ||
| 18 | 0 | ▶ | sub paths ($self) { die( ref($self) . " does not implement paths\n" ) } |
|
Subroutine
paths: not called CC=1 SCAR=6.9
Pod
documented
| |||
| 19 | |||
| 20 | # The bytes of the file at the path that it is given. A subclass must | ||
| 21 | # implement it. | ||
| 22 | # @returns Str|Undef the bytes, or C<undef> if the snapshot has no such path | ||
| 23 | # @throws when the subclass does not implement it | ||
| 24 | # @example my $text = $snapshot->content('CLAUDE.md'); | ||
| 25 | 0 | ▶ | sub content ( $self, $ ) { die( ref($self) . " does not implement content\n" ) } |
|
Subroutine
content: not called CC=1 SCAR=6.9
Pod
documented
| |||
| 26 | |||
| 27 | # Whether the snapshot has a file at C<$path>. | ||
| 28 | # @param path Str the path | ||
| 29 | # @returns Bool | ||
| 30 | # @example say 'has a profile' if $snapshot->contains('.perlcriticrc'); | ||
| 31 | 0 | ▶ | sub contains ( $self, $path ) { return exists $self->paths->{$path} } |
|
Subroutine
contains: not called CC=1 SCAR=6.9
Pod
documented
| |||
| 32 | |||
| 33 | # The git blob SHA of C<$path>. | ||
| 34 | # @param path Str the path | ||
| 35 | # @returns Str|Undef the SHA, or C<undef> when the snapshot has no such path | ||
| 36 | # @example my $sha = $snapshot->sha('git-hooks/pre-commit'); | ||
| 37 | 0 | ▶ | sub sha ( $self, $path ) { return $self->paths->{$path} } |
|
Subroutine
sha: not called CC=1 SCAR=6.9
Pod
documented
| |||
| 38 | |||
| 39 | # The paths inside C<$directory>, at any depth, relative to it and sorted. | ||
| 40 | # @param directory Str the directory, without a trailing C</> | ||
| 41 | # @returns the paths, as a list | ||
| 42 | # @example my @workflows = $snapshot->under('.github/workflows'); | ||
| 43 | 0 | ▶ | sub under ( $self, $directory ) { |
|
Subroutine
under: not called CC=1 SCAR=6.9
Pod
documented
| |||
| 44 | 0 | my $prefix = "$directory/"; | |
| 45 | 0 | my @inside = sort map { substr $_, length $prefix } grep { index( $_, $prefix ) == 0 } keys %{ $self->paths }; | |
| 46 | 0 | return @inside; | |
| 47 | } | ||
| 48 | |||
| 49 | # Whether a check can change this snapshot. False here. | ||
| 50 | # @returns Bool | ||
| 51 | # @example die "read-only\n" if !$snapshot->writable; | ||
| 52 | 0 | ▶ | sub writable ($) { return 0 } |
|
Subroutine
writable: not called CC=1 SCAR=6.9
Pod
documented
| |||
| 53 | |||
| 54 | |||
| 55 | 0 | ▶ | sub blob_sha ($bytes) { |
|
Subroutine
blob_sha: not called CC=1 SCAR=6.9
Pod
documented
| |||
| 56 | 0 | return Digest::SHA::sha1_hex( 'blob ' . length($bytes) . "\0" . $bytes ); | |
| 57 | } | ||
| 58 | |||
| 59 | __END__ | ||