| 1 | package Git::Deploy::Say; | ||||||||||||||||||||||||||||||||||||||||||
| 2 | 20 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 3 | 20 | ▶ | use warnings FATAL => "all"; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 4 | 20 | ▶ | use Exporter 'import'; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 5 | 20 | ▶ | use File::Spec::Functions qw(catfile); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||||||||||||||||
| 7 | 20 | ▶ | use POSIX 'strftime'; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 8 | 20 | ▶ | use Memoize; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||||||||||||||||
| 10 | 20 | ▶ | BEGIN { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=5 SCAR=19.6
| |||||||||||||||||||||||||||||||||||||||||||
| 11 | 20 | select( ( select(STDERR), $|++ )[0] ); $|++; # flush ALL buffers! | |||||||||||||||||||||||||||||||||||||||||
| 12 | 20 | ▶ | unless ( !$ENV{NO_COLOR} and -t STDOUT and eval "use Term::ANSIColor qw(color colored); 1" ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%2/6
not $ENV{"NO_COLOR"} and -t STDOUT and eval "use Term::ANSIColor qw(color colored); 1"
not $ENV{"NO_COLOR"} and -t STDOUT
MC/DC0%0/3
not $ENV{"NO_COLOR"} and -t STDOUT and eval "use Term::ANSIColor qw(color colored); 1"
not $ENV{"NO_COLOR"}
-t STDOUT
eval "use Term::ANSIColor qw(color colored); 1"
Truth table25%1/4
not(A) and B and C
A= not $ENV{"NO_COLOR"}B= -t STDOUTC= eval "use Term::ANSIColor qw(color colored); 1"
| |||||||||||||||||||||||||||||||||||||||||||
| 13 | 0 | ▶ | eval ' | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
color: not called CC=1 SCAR=0.6
Subroutine
colored: called CC=1 SCAR=0.6
Pod
undocumented
Pod
undocumented
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 14 | sub color { return "" } | ||||||||||||||||||||||||||||||||||||||||||
| 15 | sub colored { return $_[1] } | ||||||||||||||||||||||||||||||||||||||||||
| 16 | 1 | ||||||||||||||||||||||||||||||||||||||||||
| 17 | ' or die "Failed to installed stub color functions: $@"; | ||||||||||||||||||||||||||||||||||||||||||
| 18 | } | ||||||||||||||||||||||||||||||||||||||||||
| 19 | } | ||||||||||||||||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||||||||||||||||
| 21 | 20 | our @EXPORT = qw( | |||||||||||||||||||||||||||||||||||||||||
| 22 | _error | ||||||||||||||||||||||||||||||||||||||||||
| 23 | _die | ||||||||||||||||||||||||||||||||||||||||||
| 24 | _warn | ||||||||||||||||||||||||||||||||||||||||||
| 25 | _info | ||||||||||||||||||||||||||||||||||||||||||
| 26 | _say | ||||||||||||||||||||||||||||||||||||||||||
| 27 | _yay | ||||||||||||||||||||||||||||||||||||||||||
| 28 | _tell | ||||||||||||||||||||||||||||||||||||||||||
| 29 | _log | ||||||||||||||||||||||||||||||||||||||||||
| 30 | _print | ||||||||||||||||||||||||||||||||||||||||||
| 31 | _printf | ||||||||||||||||||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||||||||||||||||
| 33 | COLOR_WARN | ||||||||||||||||||||||||||||||||||||||||||
| 34 | COLOR_INFO | ||||||||||||||||||||||||||||||||||||||||||
| 35 | COLOR_SAY | ||||||||||||||||||||||||||||||||||||||||||
| 36 | COLOR_MODIFIED | ||||||||||||||||||||||||||||||||||||||||||
| 37 | COLOR_ADDED | ||||||||||||||||||||||||||||||||||||||||||
| 38 | COLOR_DELETED | ||||||||||||||||||||||||||||||||||||||||||
| 39 | COLOR_RENAMED | ||||||||||||||||||||||||||||||||||||||||||
| 40 | COLOR_MODECHG | ||||||||||||||||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||||||||||||||||
| 42 | color | ||||||||||||||||||||||||||||||||||||||||||
| 43 | colored | ||||||||||||||||||||||||||||||||||||||||||
| 44 | $LOG_HANDLE | ||||||||||||||||||||||||||||||||||||||||||
| 45 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||||||||||||||||
| 47 | 17 | ▶ | sub _msg { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_msg: called CC=2 SCAR=7.0
| |||||||||||||||||||||||||||||||||||||||||||
| 48 | 17 | my ( $pfx, @bits )= @_; | |||||||||||||||||||||||||||||||||||||||||
| 49 | 17 | my $msg= join "", @bits; | |||||||||||||||||||||||||||||||||||||||||
| 50 | 17 | $msg =~ s/\n*\z/\n/; | |||||||||||||||||||||||||||||||||||||||||
| 51 | 17 | $msg =~ s/^\s*#\s+//mg; | |||||||||||||||||||||||||||||||||||||||||
| 52 | 17 | ▶ | $pfx ||= "###"; | ||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$pfx ||= "###"
MC/DC0%0/1
$pfx ||= "###"
$pfx
Truth table50%1/2
A
A= $pfx
| |||||||||||||||||||||||||||||||||||||||||||
| 53 | 17 | my $qpfx= quotemeta($pfx); | |||||||||||||||||||||||||||||||||||||||||
| 54 | 17 | $msg =~ s/^(\s+$qpfx)?/$pfx /mg; | |||||||||||||||||||||||||||||||||||||||||
| 55 | 17 | return $msg; | |||||||||||||||||||||||||||||||||||||||||
| 56 | } | ||||||||||||||||||||||||||||||||||||||||||
| 57 | 20 | ▶ | use constant $ENV{WHITE_BACKGROUND} | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=2 SCAR=7.1
| |||||||||||||||||||||||||||||||||||||||||||
| 58 | ? { | ||||||||||||||||||||||||||||||||||||||||||
| 59 | 20 | ▶ | COLOR_CONFESS => 'red', | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 60 | COLOR_DIE => 'red', | ||||||||||||||||||||||||||||||||||||||||||
| 61 | COLOR_WARN => 'red', | ||||||||||||||||||||||||||||||||||||||||||
| 62 | COLOR_INFO => 'black', | ||||||||||||||||||||||||||||||||||||||||||
| 63 | COLOR_SAY => 'blue', | ||||||||||||||||||||||||||||||||||||||||||
| 64 | COLOR_TELL => 'magenta', | ||||||||||||||||||||||||||||||||||||||||||
| 65 | COLOR_YAY => 'bold black', | ||||||||||||||||||||||||||||||||||||||||||
| 66 | COLOR_MODIFIED => 'black', | ||||||||||||||||||||||||||||||||||||||||||
| 67 | COLOR_ADDED => 'green', | ||||||||||||||||||||||||||||||||||||||||||
| 68 | COLOR_DELETED => 'red', | ||||||||||||||||||||||||||||||||||||||||||
| 69 | COLOR_RENAMED => 'magenta', | ||||||||||||||||||||||||||||||||||||||||||
| 70 | COLOR_MODECHG => 'cyan', | ||||||||||||||||||||||||||||||||||||||||||
| 71 | } | ||||||||||||||||||||||||||||||||||||||||||
| 72 | : { | ||||||||||||||||||||||||||||||||||||||||||
| 73 | COLOR_CONFESS => 'bold red', | ||||||||||||||||||||||||||||||||||||||||||
| 74 | COLOR_DIE => 'bold red', | ||||||||||||||||||||||||||||||||||||||||||
| 75 | COLOR_WARN => 'bold red', | ||||||||||||||||||||||||||||||||||||||||||
| 76 | COLOR_INFO => 'white', | ||||||||||||||||||||||||||||||||||||||||||
| 77 | COLOR_SAY => 'cyan', | ||||||||||||||||||||||||||||||||||||||||||
| 78 | COLOR_TELL => 'yellow', | ||||||||||||||||||||||||||||||||||||||||||
| 79 | COLOR_YAY => 'bold white', | ||||||||||||||||||||||||||||||||||||||||||
| 80 | COLOR_MODIFIED => 'white', | ||||||||||||||||||||||||||||||||||||||||||
| 81 | COLOR_ADDED => 'green', | ||||||||||||||||||||||||||||||||||||||||||
| 82 | COLOR_DELETED => 'red', | ||||||||||||||||||||||||||||||||||||||||||
| 83 | COLOR_RENAMED => 'magenta', | ||||||||||||||||||||||||||||||||||||||||||
| 84 | COLOR_MODECHG => 'cyan', | ||||||||||||||||||||||||||||||||||||||||||
| 85 | 20 | }; | |||||||||||||||||||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||||||||||||||||||||
| 87 | 20 | ▶ | use constant SKIP_LOGGING => $ENV{GIT_DEPLOY_SAY_SKIP_LOGGING}; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||||||||||||||||
| 89 | 17 | ▶ | sub _get_log_handle { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_get_log_handle: called CC=2 SCAR=7.5
| |||||||||||||||||||||||||||||||||||||||||||
| 90 | 17 | return if SKIP_LOGGING; | |||||||||||||||||||||||||||||||||||||||||
| 91 | |||||||||||||||||||||||||||||||||||||||||||
| 92 | 17 | require Git::Deploy; | |||||||||||||||||||||||||||||||||||||||||
| 93 | 17 | my $log_dir = Git::Deploy::log_directory(); | |||||||||||||||||||||||||||||||||||||||||
| 94 | 17 | my $log_file = catfile($log_dir, 'git-deploy.log'); | |||||||||||||||||||||||||||||||||||||||||
| 95 | 17 | ▶ | open my $fh, ">>", $log_file or do { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 96 | 0 | warn "Can not append to global log file '$log_file': $!"; | |||||||||||||||||||||||||||||||||||||||||
| 97 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||
| 98 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 99 | |||||||||||||||||||||||||||||||||||||||||||
| 100 | 17 | return $fh; | |||||||||||||||||||||||||||||||||||||||||
| 101 | } | ||||||||||||||||||||||||||||||||||||||||||
| 102 | 20 | memoize('_get_log_handle'); | |||||||||||||||||||||||||||||||||||||||||
| 103 | |||||||||||||||||||||||||||||||||||||||||||
| 104 | # NOTE - THESE COLORS ARE CHOSEN WITH COLOR BLINDNESS IN MIND - DO NOT CHANGE THEM WITHOUT | ||||||||||||||||||||||||||||||||||||||||||
| 105 | # VERIFYING THAT A COLOR BLIND PROGRAMMER CAN SEE THE DIFFERENCE - 10% of MEN SUFFER SOME KIND | ||||||||||||||||||||||||||||||||||||||||||
| 106 | # OF COLOR BLINDNESS AND APPROXIMATELY 99% OF OUR CODERS ARE MEN. | ||||||||||||||||||||||||||||||||||||||||||
| 107 | |||||||||||||||||||||||||||||||||||||||||||
| 108 | 20 | our $SKIP_LOGING_DUE_TO_DEEP_RECURSION_WITH_GIT_DEPLOY_DEBUG; | |||||||||||||||||||||||||||||||||||||||||
| 109 | |||||||||||||||||||||||||||||||||||||||||||
| 110 | 17 | ▶ | sub __log { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__log: called CC=4 SCAR=14.5
| |||||||||||||||||||||||||||||||||||||||||||
| 111 | 17 | ▶ | return if $SKIP_LOGING_DUE_TO_DEEP_RECURSION_WITH_GIT_DEPLOY_DEBUG; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 112 | |||||||||||||||||||||||||||||||||||||||||||
| 113 | 17 | my $str= join("",@_); | |||||||||||||||||||||||||||||||||||||||||
| 114 | 17 | ▶ | my $user = $ENV{USER} || ((getpwuid($<))[0]); | ||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
$ENV{'USER'} || (getpwuid $<)[0]
MC/DC0%0/2
$ENV{'USER'} || (getpwuid $<)[0]
$ENV{'USER'}
(getpwuid $<)[0]
Truth table33%1/3
A || B
A= $ENV{'USER'}B= (getpwuid $<)[0]
| |||||||||||||||||||||||||||||||||||||||||||
| 115 | 17 | my $pfx= sprintf "# %-12s | %s #",$user,strftime("%Y-%m-%d %H:%M:%S",localtime); | |||||||||||||||||||||||||||||||||||||||||
| 116 | 17 | $str=~s/\033\[[^m]+m//g; # strip color | |||||||||||||||||||||||||||||||||||||||||
| 117 | 17 | $str=~s/^#([^:]+):/$pfx $1:/mg; # fix prefix | |||||||||||||||||||||||||||||||||||||||||
| 118 | 17 | $str=~s/\n*\z/\n/; | |||||||||||||||||||||||||||||||||||||||||
| 119 | 17 | ▶ | if (my $fh= _get_log_handle()) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 120 | 17 | print $fh $str; | |||||||||||||||||||||||||||||||||||||||||
| 121 | } | ||||||||||||||||||||||||||||||||||||||||||
| 122 | } | ||||||||||||||||||||||||||||||||||||||||||
| 123 | |||||||||||||||||||||||||||||||||||||||||||
| 124 | 5 | ▶ | sub __say(@) { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__say: called CC=2 SCAR=7.0
| |||||||||||||||||||||||||||||||||||||||||||
| 125 | 5 | my $color= shift; | |||||||||||||||||||||||||||||||||||||||||
| 126 | 5 | my $msg= _msg( @_ ); | |||||||||||||||||||||||||||||||||||||||||
| 127 | 5 | __log($msg); | |||||||||||||||||||||||||||||||||||||||||
| 128 | 5 | ▶ | eval { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 129 | 5 | print STDERR colored $color, $msg; | |||||||||||||||||||||||||||||||||||||||||
| 130 | 5 | 1; | |||||||||||||||||||||||||||||||||||||||||
| 131 | } or Carp::confess("wtf! $@"); | ||||||||||||||||||||||||||||||||||||||||||
| 132 | } | ||||||||||||||||||||||||||||||||||||||||||
| 133 | |||||||||||||||||||||||||||||||||||||||||||
| 134 | 0 | ▶ | sub _log(@) { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_log: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 135 | 0 | __log(_msg( "# LOG:", @_ )); | |||||||||||||||||||||||||||||||||||||||||
| 136 | } | ||||||||||||||||||||||||||||||||||||||||||
| 137 | |||||||||||||||||||||||||||||||||||||||||||
| 138 | 0 | ▶ | sub _print { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_print: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 139 | 0 | __log(_msg("#PRINT:", @_)); | |||||||||||||||||||||||||||||||||||||||||
| 140 | 0 | print @_; | |||||||||||||||||||||||||||||||||||||||||
| 141 | } | ||||||||||||||||||||||||||||||||||||||||||
| 142 | |||||||||||||||||||||||||||||||||||||||||||
| 143 | 0 | ▶ | sub _printf { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_printf: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 144 | 0 | my $fmt= shift; | |||||||||||||||||||||||||||||||||||||||||
| 145 | 0 | my $msg= sprintf $fmt, @_; # i dont think you can use @_ here alone | |||||||||||||||||||||||||||||||||||||||||
| 146 | 0 | __log(_msg("#PRINT:", $msg)); | |||||||||||||||||||||||||||||||||||||||||
| 147 | 0 | print $msg; | |||||||||||||||||||||||||||||||||||||||||
| 148 | } | ||||||||||||||||||||||||||||||||||||||||||
| 149 | |||||||||||||||||||||||||||||||||||||||||||
| 150 | |||||||||||||||||||||||||||||||||||||||||||
| 151 | 0 | ▶ | sub _confess(@) { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_confess: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 152 | 0 | my $msg= Carp::longmess(); | |||||||||||||||||||||||||||||||||||||||||
| 153 | 0 | $msg= _msg( "# FATAL:", @_, $msg ); | |||||||||||||||||||||||||||||||||||||||||
| 154 | 0 | __log($msg); | |||||||||||||||||||||||||||||||||||||||||
| 155 | 0 | die colored [COLOR_CONFESS], $msg; | |||||||||||||||||||||||||||||||||||||||||
| 156 | } # very bad | ||||||||||||||||||||||||||||||||||||||||||
| 157 | |||||||||||||||||||||||||||||||||||||||||||
| 158 | 12 | ▶ | sub _die(@) { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_die: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 159 | # very bad | ||||||||||||||||||||||||||||||||||||||||||
| 160 | 12 | my $msg= _msg( "# FATAL:", @_ ); | |||||||||||||||||||||||||||||||||||||||||
| 161 | 12 | __log($msg); | |||||||||||||||||||||||||||||||||||||||||
| 162 | 12 | chomp $msg; | |||||||||||||||||||||||||||||||||||||||||
| 163 | 12 | die colored([COLOR_DIE], $msg), "\n"; | |||||||||||||||||||||||||||||||||||||||||
| 164 | } | ||||||||||||||||||||||||||||||||||||||||||
| 165 | |||||||||||||||||||||||||||||||||||||||||||
| 166 | 0 | ▶ | sub _error(@) { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_error: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 167 | 0 | __say( [COLOR_DIE], "# ERROR:", @_ ); | |||||||||||||||||||||||||||||||||||||||||
| 168 | } # still bad, but not fatal | ||||||||||||||||||||||||||||||||||||||||||
| 169 | |||||||||||||||||||||||||||||||||||||||||||
| 170 | |||||||||||||||||||||||||||||||||||||||||||
| 171 | 0 | ▶ | sub _warn(@) { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_warn: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 172 | 0 | __say([COLOR_WARN], "# WARN :", @_ ); | |||||||||||||||||||||||||||||||||||||||||
| 173 | } # bad | ||||||||||||||||||||||||||||||||||||||||||
| 174 | |||||||||||||||||||||||||||||||||||||||||||
| 175 | 0 | ▶ | sub _info(@) { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_info: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 176 | 0 | __say([COLOR_INFO], "# INFO :", @_ ); | |||||||||||||||||||||||||||||||||||||||||
| 177 | } # diags | ||||||||||||||||||||||||||||||||||||||||||
| 178 | |||||||||||||||||||||||||||||||||||||||||||
| 179 | 5 | ▶ | sub _say(@) { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_say: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 180 | 5 | __say([COLOR_SAY], "# NOTE :", @_ ); | |||||||||||||||||||||||||||||||||||||||||
| 181 | } # ok | ||||||||||||||||||||||||||||||||||||||||||
| 182 | |||||||||||||||||||||||||||||||||||||||||||
| 183 | 0 | ▶ | sub _yay(@) { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_yay: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 184 | 0 | __say([COLOR_YAY], "# YAY :", @_ ); | |||||||||||||||||||||||||||||||||||||||||
| 185 | } # great | ||||||||||||||||||||||||||||||||||||||||||
| 186 | |||||||||||||||||||||||||||||||||||||||||||
| 187 | 0 | ▶ | sub _tell(@) { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_tell: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 188 | 0 | __say( [COLOR_TELL], "# USER :", @_ ); | |||||||||||||||||||||||||||||||||||||||||
| 189 | } # tell user to do something | ||||||||||||||||||||||||||||||||||||||||||
| 190 | |||||||||||||||||||||||||||||||||||||||||||
| 191 | 20 | 1; | |||||||||||||||||||||||||||||||||||||||||