| 1 | package Dist::Conformance::Update 0.011; | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | # ABSTRACT: What an update changed, or would change, in a checkout, and what it left to a person | ||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||
| 5 | 2 | ▶ | use 5.040; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | 2 | ▶ | use warnings FATAL => 'all'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | 2 | ▶ | use re '/aasx'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | 2 | ▶ | use Mojo::Base -base, -signatures; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||
| 11 | 2 | has 'snapshot'; | |||||||||||||||||||||||||||
| 12 | 2 | has dry_run => 0; | |||||||||||||||||||||||||||
| 13 | 0 | ▶ | has changes => sub { [] }; | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=1.2
| |||||||||||||||||||||||||||||
| 14 | 0 | ▶ | has manual => sub { [] }; | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=1.2
| |||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||
| 17 | 0 | ▶ | sub new ( $class, @args ) { | ||||||||||||||||||||||||||
|
Subroutine
new: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||||||||||||||||
| 18 | 0 | my $self = $class->SUPER::new(@args); | |||||||||||||||||||||||||||
| 19 | 0 | my $snapshot = $self->snapshot; | |||||||||||||||||||||||||||
| 20 | 0 | ▶ | die "An update needs a snapshot that it can write, such as a Dist::Conformance::Snapshot::Directory\n" if !$snapshot || !$snapshot->writable; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$snapshot and $snapshot->writable
MC/DC0%0/2
$snapshot and $snapshot->writable
$snapshot
$snapshot->writable
Truth table0%0/3
A and B
A= $snapshotB= $snapshot->writable
| |||||||||||||||||||||||||||||
| 21 | 0 | return $self; | |||||||||||||||||||||||||||
| 22 | } | ||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||
| 24 | # Writes C<$bytes> to C<$path> in the snapshot, with C<$mode>, and records a | ||||||||||||||||||||||||||||
| 25 | # C<create> or a C<replace>. A file that already has these bytes is left alone, | ||||||||||||||||||||||||||||
| 26 | # and nothing is recorded, so a second update after the first has nothing to do. | ||||||||||||||||||||||||||||
| 27 | # @param path Str the path, relative to the top of the checkout | ||||||||||||||||||||||||||||
| 28 | # @param bytes Str the content | ||||||||||||||||||||||||||||
| 29 | # @param mode Int optional: the permissions, default 0644 | ||||||||||||||||||||||||||||
| 30 | # @returns Bool whether it recorded a change | ||||||||||||||||||||||||||||
| 31 | # @throws when the snapshot cannot write the file, as | ||||||||||||||||||||||||||||
| 32 | # L<Dist::Conformance::Snapshot::Directory/"write(path, bytes, mode)"> says | ||||||||||||||||||||||||||||
| 33 | # @example $update->write( '.perltidyrc', "-l=400\n" ); | ||||||||||||||||||||||||||||
| 34 | 0 | ▶ | sub write ( $self, $path, $bytes, $mode = oct 644 ) { ## no critic (Subroutines::ProhibitBuiltinHomonyms) -- a method, never called as the builtin | ||||||||||||||||||||||||||
|
Subroutine
write: not called CC=6 SCAR=37.4
Pod
documented
| |||||||||||||||||||||||||||||
| 35 | 0 | my $snapshot = $self->snapshot; | |||||||||||||||||||||||||||
| 36 | 0 | my $old = $snapshot->content($path); | |||||||||||||||||||||||||||
| 37 | 0 | ▶ | return 0 if defined $old && $old eq $bytes; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
defined $old and $old eq $bytes
MC/DC0%0/2
defined $old and $old eq $bytes
defined $old
$old eq $bytes
Truth table0%0/3
A and B
A= defined $oldB= $old eq $bytes
| |||||||||||||||||||||||||||||
| 38 | 0 | ▶ | $snapshot->write( $path, $bytes, $mode ) if !$self->dry_run; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 39 | 0 | ▶ | push @{ $self->changes }, { action => defined $old ? 'replace' : 'create', path => $path }; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 40 | 0 | return 1; | |||||||||||||||||||||||||||
| 41 | } | ||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||
| 43 | # Installs C<$bytes> as the git hook C<$name> of the checkout, and records an | ||||||||||||||||||||||||||||
| 44 | # C<install> of the hook's path, unless the hook that is installed has these | ||||||||||||||||||||||||||||
| 45 | # bytes already. When the snapshot is not a git checkout, it records a line for | ||||||||||||||||||||||||||||
| 46 | # L</manual> instead. | ||||||||||||||||||||||||||||
| 47 | # @param name Str the name of the hook, such as C<pre-commit> | ||||||||||||||||||||||||||||
| 48 | # @param bytes Str the content of the hook | ||||||||||||||||||||||||||||
| 49 | # @returns Bool whether it recorded an C<install> | ||||||||||||||||||||||||||||
| 50 | # @throws when the snapshot cannot install the hook, as | ||||||||||||||||||||||||||||
| 51 | # L<Dist::Conformance::Snapshot::Directory/"install_hook(name, bytes)"> says | ||||||||||||||||||||||||||||
| 52 | # @example $update->install_hook( 'pre-commit', $bytes ); | ||||||||||||||||||||||||||||
| 53 | 0 | ▶ | sub install_hook ( $self, $name, $bytes ) { | ||||||||||||||||||||||||||
|
Subroutine
install_hook: not called CC=5 SCAR=34.0
Pod
documented
| |||||||||||||||||||||||||||||
| 54 | 0 | my $snapshot = $self->snapshot; | |||||||||||||||||||||||||||
| 55 | 0 | my $dir = $snapshot->hooks_dir; | |||||||||||||||||||||||||||
| 56 | 0 | ▶ | if ( !defined $dir ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 57 | 0 | $self->by_hand( 'Install the hook ' . $name . ': ' . $snapshot->root . ' is not a git checkout' ); | |||||||||||||||||||||||||||
| 58 | 0 | return 0; | |||||||||||||||||||||||||||
| 59 | } | ||||||||||||||||||||||||||||
| 60 | 0 | my $installed = $snapshot->installed_hook($name); | |||||||||||||||||||||||||||
| 61 | 0 | ▶ | return 0 if defined $installed && $installed eq $bytes; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
defined $installed and $installed eq $bytes
MC/DC0%0/2
defined $installed and $installed eq $bytes
defined $installed
$installed eq $bytes
Truth table0%0/3
A and B
A= defined $installedB= $installed eq $bytes
| |||||||||||||||||||||||||||||
| 62 | 0 | ▶ | $snapshot->install_hook( $name, $bytes ) if !$self->dry_run; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 63 | 0 | my $hook = $dir->child($name); | |||||||||||||||||||||||||||
| 64 | 0 | push @{ $self->changes }, { action => 'install', path => $hook->to_rel( $snapshot->root )->to_string }; | |||||||||||||||||||||||||||
| 65 | 0 | return 1; | |||||||||||||||||||||||||||
| 66 | } | ||||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||
| 69 | 0 | ▶ | sub by_hand ( $self, @sentences ) { | ||||||||||||||||||||||||||
|
Subroutine
by_hand: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 70 | 0 | push @{ $self->manual }, @sentences; | |||||||||||||||||||||||||||
| 71 | 0 | return; | |||||||||||||||||||||||||||
| 72 | } | ||||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||
| 74 | __END__ | ||||||||||||||||||||||||||||