| 1 | package App::githook::perltidy; | ||||||||||||||||||||||||||||
| 2 | 20 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 3 | 20 | ▶ | use Path::Tiny; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | use App::githook::perltidy_CI | ||||||||||||||||||||||||||||
| 5 | 20 | ▶ | abstract => 1, | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | has => { | ||||||||||||||||||||||||||||
| 7 | repo => { | ||||||||||||||||||||||||||||
| 8 | init_arg => undef, | ||||||||||||||||||||||||||||
| 9 | 20 | ▶ | default => sub { path( $ENV{GIT_DIR} )->absolute->parent }, | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 10 | }, | ||||||||||||||||||||||||||||
| 11 | pre_commit => { | ||||||||||||||||||||||||||||
| 12 | init_arg => undef, | ||||||||||||||||||||||||||||
| 13 | 15 | ▶ | default => sub { $_[0]->repo->child( '.git', 'hooks', 'pre-commit' ) }, | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 14 | }, | ||||||||||||||||||||||||||||
| 15 | skip_list => { | ||||||||||||||||||||||||||||
| 16 | init_arg => undef, | ||||||||||||||||||||||||||||
| 17 | 17 | ▶ | default => sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=8.4
| |||||||||||||||||||||||||||||
| 18 | 17 | my $self = shift; | |||||||||||||||||||||||||||
| 19 | 17 | my $skipfile = $self->repo->child('MANIFEST.SKIP'); | |||||||||||||||||||||||||||
| 20 | 0 | ▶ | [ map { chomp; $_ } $skipfile->exists ? $skipfile->lines : () ]; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 21 | }, | ||||||||||||||||||||||||||||
| 22 | }, | ||||||||||||||||||||||||||||
| 23 | perlcriticrc => { | ||||||||||||||||||||||||||||
| 24 | init_arg => undef, | ||||||||||||||||||||||||||||
| 25 | lazy => 0, | ||||||||||||||||||||||||||||
| 26 | 26 | ▶ | default => sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 27 | 26 | my $self = shift; | |||||||||||||||||||||||||||
| 28 | 26 | $self->have_committed( $self->repo->child('.perlcriticrc') ); | |||||||||||||||||||||||||||
| 29 | }, | ||||||||||||||||||||||||||||
| 30 | }, | ||||||||||||||||||||||||||||
| 31 | perltidyrc => { | ||||||||||||||||||||||||||||
| 32 | init_arg => undef, | ||||||||||||||||||||||||||||
| 33 | lazy => 0, | ||||||||||||||||||||||||||||
| 34 | 21 | ▶ | default => sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||
| 35 | 21 | my $self = shift; | |||||||||||||||||||||||||||
| 36 | 21 | ▶ | $self->have_committed( $self->repo->child('.perltidyrc.sweetened') ) | ||||||||||||||||||||||||||
|
Condition100%3/3
$self->have_committed($self->repo->child(".perltidyrc.sweetened")) // $self->have_committed($self->repo->child(".perltidyrc"))
MC/DC100%2/2
$self->have_committed($self->repo->child(".perltidyrc.sweetened")) // $self->have_committed($self->repo->child(".perltidyrc"))
$self->have_committed($self->repo->child(".perltidyrc.sweetened"))
$self->have_committed($self->repo->child(".perltidyrc"))
Truth table100%3/3
A // B
A= $self->have_committed($self->repo->child(".perltidyrc.sweetened"))B= $self->have_committed($self->repo->child(".perltidyrc"))
| |||||||||||||||||||||||||||||
| 37 | // $self->have_committed( $self->repo->child('.perltidyrc') ); | ||||||||||||||||||||||||||||
| 38 | }, | ||||||||||||||||||||||||||||
| 39 | }, | ||||||||||||||||||||||||||||
| 40 | podtidyrc => { | ||||||||||||||||||||||||||||
| 41 | init_arg => undef, | ||||||||||||||||||||||||||||
| 42 | lazy => 0, | ||||||||||||||||||||||||||||
| 43 | 27 | ▶ | default => sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 44 | 27 | my $self = shift; | |||||||||||||||||||||||||||
| 45 | 27 | $self->have_committed( $self->repo->child('.podtidy-opts') ); | |||||||||||||||||||||||||||
| 46 | }, | ||||||||||||||||||||||||||||
| 47 | }, | ||||||||||||||||||||||||||||
| 48 | podtidyrc_opts => { | ||||||||||||||||||||||||||||
| 49 | init_arg => undef, | ||||||||||||||||||||||||||||
| 50 | 2 | ▶ | default => sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||
| 51 | 2 | my $self = shift; | |||||||||||||||||||||||||||
| 52 | 2 | my $pod_opts = {}; | |||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||
| 54 | 2 | ▶ | if ( my $rc = $self->podtidyrc ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 55 | 2 | foreach my $line ( $rc->lines ) { | |||||||||||||||||||||||||||
| 56 | 2 | chomp $line; | |||||||||||||||||||||||||||
| 57 | 2 | $line =~ s/^--//; | |||||||||||||||||||||||||||
| 58 | 2 | my ( $opt, $arg ) = split / /, $line; | |||||||||||||||||||||||||||
| 59 | 2 | $pod_opts->{$opt} = $arg; | |||||||||||||||||||||||||||
| 60 | } | ||||||||||||||||||||||||||||
| 61 | } | ||||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||
| 63 | 2 | $pod_opts; | |||||||||||||||||||||||||||
| 64 | }, | ||||||||||||||||||||||||||||
| 65 | }, | ||||||||||||||||||||||||||||
| 66 | readme_from => { | ||||||||||||||||||||||||||||
| 67 | init_arg => undef, | ||||||||||||||||||||||||||||
| 68 | lazy => 0, | ||||||||||||||||||||||||||||
| 69 | 25 | ▶ | default => sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=4 SCAR=14.1
| |||||||||||||||||||||||||||||
| 70 | 25 | my $self = shift; | |||||||||||||||||||||||||||
| 71 | 25 | ▶ | my $rf = $self->have_committed( $self->repo->child('.readme_from') ) | ||||||||||||||||||||||||||
|
Condition100%2/2
$self->have_committed($self->repo->child(".readme_from")) // (return)
MC/DC100%1/1
$self->have_committed($self->repo->child(".readme_from")) // (return)
$self->have_committed($self->repo->child(".readme_from"))
Truth table100%2/2
A
A= $self->have_committed($self->repo->child(".readme_from"))
| |||||||||||||||||||||||||||||
| 72 | // return; | ||||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||
| 74 | 1 | ($rf) = $rf->lines_utf8( { chomp => 1, count => 1, } ); | |||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||
| 76 | 1 | ▶ | die ".readme_from appears to be empty?\n" unless $rf; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 77 | |||||||||||||||||||||||||||||
| 78 | 1 | ▶ | $self->have_committed( path($rf), 0 ) | ||||||||||||||||||||||||||
|
Condition50%1/2
$self->have_committed(path($rf), 0) // die(".readme_from points to a missing file: $rf\n")
MC/DC0%0/1
$self->have_committed(path($rf), 0) // die(".readme_from points to a missing file: $rf\n")
$self->have_committed(path($rf), 0)
Truth table50%1/2
A
A= $self->have_committed(path($rf), 0)
| |||||||||||||||||||||||||||||
| 79 | // die ".readme_from points to a missing file: $rf\n"; | ||||||||||||||||||||||||||||
| 80 | }, | ||||||||||||||||||||||||||||
| 81 | }, | ||||||||||||||||||||||||||||
| 82 | sweetened => { | ||||||||||||||||||||||||||||
| 83 | init_arg => undef, | ||||||||||||||||||||||||||||
| 84 | 16 | ▶ | default => sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 85 | 16 | my $self = shift; | |||||||||||||||||||||||||||
| 86 | 16 | $self->perltidyrc =~ m/\.sweetened$/; | |||||||||||||||||||||||||||
| 87 | }, | ||||||||||||||||||||||||||||
| 88 | }, | ||||||||||||||||||||||||||||
| 89 | 20 | verbose => {}, | |||||||||||||||||||||||||||
| 90 | 20 | }; | |||||||||||||||||||||||||||
| 91 | |||||||||||||||||||||||||||||
| 92 | 20 | our $VERSION = '1.0.1'; | |||||||||||||||||||||||||||
| 93 | |||||||||||||||||||||||||||||
| 94 | 20 | ▶ | BEGIN { | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=3 SCAR=11.1
| |||||||||||||||||||||||||||||
| 95 | # Both of these start out as relative which breaks when we want to | ||||||||||||||||||||||||||||
| 96 | # modify the repo and index from a different working tree | ||||||||||||||||||||||||||||
| 97 | 20 | ▶ | $ENV{GIT_DIR} = path( $ENV{GIT_DIR} || '.git' )->absolute; | ||||||||||||||||||||||||||
|
Condition50%1/2
$ENV{'GIT_DIR'} || '.git'
MC/DC0%0/1
$ENV{'GIT_DIR'} || '.git'
$ENV{'GIT_DIR'}
Truth table50%1/2
A
A= $ENV{'GIT_DIR'}
| |||||||||||||||||||||||||||||
| 98 | $ENV{GIT_INDEX_FILE} = path( $ENV{GIT_INDEX_FILE} )->absolute->stringify | ||||||||||||||||||||||||||||
| 99 | 20 | ▶ | if $ENV{GIT_INDEX_FILE}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 100 | } | ||||||||||||||||||||||||||||
| 101 | |||||||||||||||||||||||||||||
| 102 | 17 | ▶ | sub BUILD { | ||||||||||||||||||||||||||
|
Subroutine
BUILD: called CC=4 SCAR=13.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 103 | 17 | my $self = shift; | |||||||||||||||||||||||||||
| 104 | |||||||||||||||||||||||||||||
| 105 | 17 | ▶ | die ".perltidyrc[.sweetened] missing from repository.\n" | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 106 | unless $self->perltidyrc; | ||||||||||||||||||||||||||||
| 107 | |||||||||||||||||||||||||||||
| 108 | 16 | ▶ | die ".perltidyrc and .perltidyrc.sweetened are incompatible\n" | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$self->sweetened and $self->have_committed($self->repo->child(".perltidyrc"))
MC/DC50%1/2
$self->sweetened and $self->have_committed($self->repo->child(".perltidyrc"))
$self->sweetened
$self->have_committed($self->repo->child(".perltidyrc"))
Truth table66%2/3
A and B
A= $self->sweetenedB= $self->have_committed($self->repo->child(".perltidyrc"))
| |||||||||||||||||||||||||||||
| 109 | if $self->sweetened | ||||||||||||||||||||||||||||
| 110 | and $self->have_committed( $self->repo->child('.perltidyrc') ); | ||||||||||||||||||||||||||||
| 111 | } | ||||||||||||||||||||||||||||
| 112 | |||||||||||||||||||||||||||||
| 113 | 120 | ▶ | sub have_committed { | ||||||||||||||||||||||||||
|
Subroutine
have_committed: called CC=7 SCAR=20.4
Pod
undocumented
| |||||||||||||||||||||||||||||
| 114 | 120 | my $self = shift; | |||||||||||||||||||||||||||
| 115 | 120 | my $file = shift; | |||||||||||||||||||||||||||
| 116 | 120 | ▶ | my $manifest_check = shift // 1; | ||||||||||||||||||||||||||
|
Condition100%2/2
shift() // 1
MC/DC100%1/1
shift() // 1
shift()
Truth table100%2/2
A
A= shift()
| |||||||||||||||||||||||||||||
| 117 | |||||||||||||||||||||||||||||
| 118 | 120 | ▶ | if ( -e $file ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 119 | 26 | my $basename = $file->basename; | |||||||||||||||||||||||||||
| 120 | 26 | ▶ | die $basename . " is not committed.\n" | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 121 | unless system( | ||||||||||||||||||||||||||||
| 122 | 'git ls-files --error-unmatch "' . $file . '" > /dev/null 2>&1' ) | ||||||||||||||||||||||||||||
| 123 | == 0; | ||||||||||||||||||||||||||||
| 124 | |||||||||||||||||||||||||||||
| 125 | 23 | ▶ | if ( $manifest_check and my @skip_list = @{ $self->skip_list } ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$manifest_check and my(@skip_list) = @{$self->skip_list;}
MC/DC0%0/2
$manifest_check and my(@skip_list) = @{$self->skip_list;}
$manifest_check
my(@skip_list) = @{$self->skip_list;}
Truth table66%2/3
A and B
A= $manifest_checkB= my(@skip_list) = @{$self->skip_list;}
| |||||||||||||||||||||||||||||
| 126 | warn "githook-perltidy: MANIFEST.SKIP does not cover $basename\n" | ||||||||||||||||||||||||||||
| 127 | 0 | ▶ | unless grep { $basename =~ m/$_/ } @skip_list; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 128 | } | ||||||||||||||||||||||||||||
| 129 | |||||||||||||||||||||||||||||
| 130 | 23 | return $file; | |||||||||||||||||||||||||||
| 131 | } | ||||||||||||||||||||||||||||
| 132 | |||||||||||||||||||||||||||||
| 133 | 94 | return; | |||||||||||||||||||||||||||
| 134 | } | ||||||||||||||||||||||||||||
| 135 | |||||||||||||||||||||||||||||
| 136 | 20 | 1; | |||||||||||||||||||||||||||
| 137 | |||||||||||||||||||||||||||||
| 138 | __END__ | ||||||||||||||||||||||||||||