| 1 | package App::GitFind::Base; | ||||||||||||||||||||
| 2 | |||||||||||||||||||||
| 3 | 5 | ▶ | use 5.010; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 4 | 5 | ▶ | use strict; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 5 | 5 | ▶ | use warnings; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 6 | |||||||||||||||||||||
| 7 | 5 | our $VERSION = '0.000002'; | |||||||||||||||||||
| 8 | |||||||||||||||||||||
| 9 | 5 | ▶ | use parent 'Exporter'; # TODO use Exporter::Tidy instead? | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 10 | 5 | ▶ | use vars::i [ | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 11 | 5 | '$VERBOSE' => 0, | |||||||||||||||||||
| 12 | '$QUIET' => 0, | ||||||||||||||||||||
| 13 | '@EXPORT' => [qw(true false | ||||||||||||||||||||
| 14 | croak ddc getparameters *QUIET _qwc *VERBOSE vlog vwarn)], | ||||||||||||||||||||
| 15 | 5 | ]; | |||||||||||||||||||
| 16 | |||||||||||||||||||||
| 17 | #use Import::Into; | ||||||||||||||||||||
| 18 | |||||||||||||||||||||
| 19 | 5 | ▶ | use constant { true => !!1, false => !!0 }; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 20 | |||||||||||||||||||||
| 21 | # Re-exports | ||||||||||||||||||||
| 22 | #use Carp qw(confess); | ||||||||||||||||||||
| 23 | #use Data::Dumper::Compact (); | ||||||||||||||||||||
| 24 | #use Getargs::Mixed; | ||||||||||||||||||||
| 25 | |||||||||||||||||||||
| 26 | # === Documentation === {{{1 | ||||||||||||||||||||
| 27 | |||||||||||||||||||||
| 28 | =head1 NAME | ||||||||||||||||||||
| 29 | |||||||||||||||||||||
| 30 | App::GitFind::Base - base definitions for App::GitFind | ||||||||||||||||||||
| 31 | |||||||||||||||||||||
| 32 | =head1 SYNOPSIS | ||||||||||||||||||||
| 33 | |||||||||||||||||||||
| 34 | use App::GitFind::Base; | ||||||||||||||||||||
| 35 | |||||||||||||||||||||
| 36 | Imports the functions described herein. Does not set L<strict> and L<warnings> | ||||||||||||||||||||
| 37 | in the caller, since invoking modules have to do so on their own anyway for the | ||||||||||||||||||||
| 38 | sake of Kwalitee. | ||||||||||||||||||||
| 39 | |||||||||||||||||||||
| 40 | =head1 VARIABLES | ||||||||||||||||||||
| 41 | |||||||||||||||||||||
| 42 | =head2 $QUIET | ||||||||||||||||||||
| 43 | |||||||||||||||||||||
| 44 | Set to a truthy value to disable logging via L</vlog>. Overrides L</$VERBOSE>. | ||||||||||||||||||||
| 45 | Exported as C<*QUIET> so that it can be C<local>ized. | ||||||||||||||||||||
| 46 | |||||||||||||||||||||
| 47 | =head2 $VERBOSE | ||||||||||||||||||||
| 48 | |||||||||||||||||||||
| 49 | Set to a positive integer to enable logging via L</vlog>. | ||||||||||||||||||||
| 50 | Exported as C<*VERBOSE> so that it can be C<local>ized. | ||||||||||||||||||||
| 51 | |||||||||||||||||||||
| 52 | =head1 FUNCTIONS | ||||||||||||||||||||
| 53 | |||||||||||||||||||||
| 54 | =cut | ||||||||||||||||||||
| 55 | |||||||||||||||||||||
| 56 | # }}}1 | ||||||||||||||||||||
| 57 | |||||||||||||||||||||
| 58 | =head2 _qwc | ||||||||||||||||||||
| 59 | |||||||||||||||||||||
| 60 | qw(), but permitting comments. Call as C<< _qwc(<<EOT) >>. Thanks to ideas at | ||||||||||||||||||||
| 61 | https://www.perlmonks.org/?node=qw%20comments . Prototyped as C<($)>. | ||||||||||||||||||||
| 62 | |||||||||||||||||||||
| 63 | Has a leading underscore because for some reason that makes my syntax files | ||||||||||||||||||||
| 64 | happier! | ||||||||||||||||||||
| 65 | |||||||||||||||||||||
| 66 | =cut | ||||||||||||||||||||
| 67 | |||||||||||||||||||||
| 68 | 20 | ▶ | sub _qwc ($) { | ||||||||||||||||||
|
Subroutine
_qwc: called CC=3 SCAR=11.0
| |||||||||||||||||||||
| 69 | 20 | my @retval; | |||||||||||||||||||
| 70 | 20 | ▶ | for(split "\n", $_[0]//'') { | ||||||||||||||||||
|
Condition50%1/2
$_[0] // ""
MC/DC0%0/1
$_[0] // ""
$_[0]
Truth table50%1/2
A
A= $_[0]
| |||||||||||||||||||||
| 71 | 70 | chomp; | |||||||||||||||||||
| 72 | 70 | s{#.*$}{}; # Remove comments | |||||||||||||||||||
| 73 | 70 | s{(?:^\s+)|(?:\s+$)}{}g; # Remove leading/trailing ws | |||||||||||||||||||
| 74 | 70 | push @retval, grep { length } split /\s+/; | |||||||||||||||||||
| 75 | } | ||||||||||||||||||||
| 76 | 20 | return @retval; | |||||||||||||||||||
| 77 | } #_qwc() | ||||||||||||||||||||
| 78 | |||||||||||||||||||||
| 79 | =head2 getparameters | ||||||||||||||||||||
| 80 | |||||||||||||||||||||
| 81 | An alias of the C<parameters()> function from L<Getargs::Mixed>, but with | ||||||||||||||||||||
| 82 | C<-undef_ok> set. | ||||||||||||||||||||
| 83 | |||||||||||||||||||||
| 84 | =cut | ||||||||||||||||||||
| 85 | |||||||||||||||||||||
| 86 | 0 | ▶ | sub getparameters { | ||||||||||||||||||
|
Subroutine
getparameters: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||
| 87 | 0 | state $GM = (require Getargs::Mixed, Getargs::Mixed->new(-undef_ok => true)); | |||||||||||||||||||
| 88 | |||||||||||||||||||||
| 89 | 0 | unshift @_, $GM; | |||||||||||||||||||
| 90 | 0 | goto &Getargs::Mixed::parameters; | |||||||||||||||||||
| 91 | } #getparameters() | ||||||||||||||||||||
| 92 | |||||||||||||||||||||
| 93 | =head2 ddc | ||||||||||||||||||||
| 94 | |||||||||||||||||||||
| 95 | L<Data::Dumper::Compact/ddc>, but lazily loads C<Data::Dumper::Compact>. | ||||||||||||||||||||
| 96 | |||||||||||||||||||||
| 97 | =cut | ||||||||||||||||||||
| 98 | |||||||||||||||||||||
| 99 | 0 | ▶ | sub ddc { | ||||||||||||||||||
|
Subroutine
ddc: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||
| 100 | 0 | state $dumpcb = (require Data::Dumper::Compact, Data::Dumper::Compact->new->dump_cb); | |||||||||||||||||||
| 101 | 0 | goto &$dumpcb; | |||||||||||||||||||
| 102 | } | ||||||||||||||||||||
| 103 | |||||||||||||||||||||
| 104 | =head2 croak | ||||||||||||||||||||
| 105 | |||||||||||||||||||||
| 106 | As L<Carp/croak>, but lazily loads C<Carp>. | ||||||||||||||||||||
| 107 | |||||||||||||||||||||
| 108 | =cut | ||||||||||||||||||||
| 109 | |||||||||||||||||||||
| 110 | 0 | ▶ | sub croak { | ||||||||||||||||||
|
Subroutine
croak: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||
| 111 | 0 | require Carp; | |||||||||||||||||||
| 112 | 0 | goto &Carp::croak; | |||||||||||||||||||
| 113 | } | ||||||||||||||||||||
| 114 | |||||||||||||||||||||
| 115 | =head2 vlog | ||||||||||||||||||||
| 116 | |||||||||||||||||||||
| 117 | Log information to STDERR if L</$VERBOSE> is set. Usage: | ||||||||||||||||||||
| 118 | |||||||||||||||||||||
| 119 | vlog { <list of things to log> } | ||||||||||||||||||||
| 120 | [optional min verbosity level (default 1)] | ||||||||||||||||||||
| 121 | [, log-routine args]; | ||||||||||||||||||||
| 122 | |||||||||||||||||||||
| 123 | The items in the list are joined by C<' '> on output, and a C<'\n'> is added. | ||||||||||||||||||||
| 124 | Each line is prefixed with C<'# '> for the benefit of test runs. | ||||||||||||||||||||
| 125 | To break the list across multiple lines, specify C<\n> at the beginning of | ||||||||||||||||||||
| 126 | a list item. | ||||||||||||||||||||
| 127 | |||||||||||||||||||||
| 128 | The list is in C<{}> so that it won't be evaluated if logging is turned off. | ||||||||||||||||||||
| 129 | It is a full block, so you can run arbitrary code to decide what to log. | ||||||||||||||||||||
| 130 | If the block returns an empty list, vlog will not produce any output. | ||||||||||||||||||||
| 131 | However, if the block returns at least one element, vlog will produce at | ||||||||||||||||||||
| 132 | least a C<'# '>. | ||||||||||||||||||||
| 133 | |||||||||||||||||||||
| 134 | The message will be output only if L</$VERBOSE> is at least the given minimum | ||||||||||||||||||||
| 135 | verbosity level (1 by default). | ||||||||||||||||||||
| 136 | |||||||||||||||||||||
| 137 | If C<< $VERBOSE >= 4 >>, the filename and line from which vlog was called | ||||||||||||||||||||
| 138 | will also be printed. | ||||||||||||||||||||
| 139 | |||||||||||||||||||||
| 140 | If more arguments are provided than two, the extras are the arguments | ||||||||||||||||||||
| 141 | to the subroutine. This permits you to pass arguments from the caller's | ||||||||||||||||||||
| 142 | C<@_> that would otherwise be shadowed inside the logging routine. E.g.: | ||||||||||||||||||||
| 143 | |||||||||||||||||||||
| 144 | sub foo { | ||||||||||||||||||||
| 145 | vlog { $_[0] } 1, $_[1]; # log foo's $_[1] | ||||||||||||||||||||
| 146 | } | ||||||||||||||||||||
| 147 | |||||||||||||||||||||
| 148 | =cut | ||||||||||||||||||||
| 149 | |||||||||||||||||||||
| 150 | 0 | ▶ | sub vlog (&;@) { | ||||||||||||||||||
|
Subroutine
vlog: not called CC=7 SCAR=40.3
Pod
documented
| |||||||||||||||||||||
| 151 | 0 | ▶ | return if $QUIET; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 152 | 0 | my ($crRoutine, $level) = splice @_, 0, 2; | |||||||||||||||||||
| 153 | 0 | ▶ | return unless $VERBOSE >= ($level // 1); | ||||||||||||||||||
|
Branch: 1 branch
Condition0%0/2
$level // 1
MC/DC0%0/1
$level // 1
$level
Truth table0%0/2
A
A= $level
| |||||||||||||||||||||
| 154 | |||||||||||||||||||||
| 155 | 0 | my @log = $crRoutine->(@_); | |||||||||||||||||||
| 156 | 0 | ▶ | return unless @log; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 157 | |||||||||||||||||||||
| 158 | 0 | ▶ | chomp $log[$#log] if $log[$#log]; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 159 | # TODO add an option to number the lines of the output | ||||||||||||||||||||
| 160 | 0 | my $msg = join(' ', @log); | |||||||||||||||||||
| 161 | 0 | $msg =~ s/^/# /gm; | |||||||||||||||||||
| 162 | |||||||||||||||||||||
| 163 | 0 | ▶ | if($VERBOSE >= 4) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 164 | 0 | my ($package, $filename, $line) = caller; | |||||||||||||||||||
| 165 | 0 | $msg .= " (at $filename:$line)"; | |||||||||||||||||||
| 166 | } | ||||||||||||||||||||
| 167 | |||||||||||||||||||||
| 168 | 0 | say STDERR $msg; | |||||||||||||||||||
| 169 | } #vlog() | ||||||||||||||||||||
| 170 | |||||||||||||||||||||
| 171 | =head2 vwarn | ||||||||||||||||||||
| 172 | |||||||||||||||||||||
| 173 | As L</vlog>, but warns regardless of L</$VERBOSE>. Does respect L</$QUIET>. | ||||||||||||||||||||
| 174 | |||||||||||||||||||||
| 175 | =cut | ||||||||||||||||||||
| 176 | |||||||||||||||||||||
| 177 | 0 | ▶ | sub vwarn (&) { | ||||||||||||||||||
|
Subroutine
vwarn: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||||||||
| 178 | 0 | ▶ | return if $QUIET; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 179 | |||||||||||||||||||||
| 180 | 0 | my @log = &{$_[0]}(); | |||||||||||||||||||
| 181 | 0 | ▶ | return unless @log; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 182 | |||||||||||||||||||||
| 183 | 0 | ▶ | vlog { "Warning:", @log } $VERBOSE; | ||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||
| 184 | } #vwarn() | ||||||||||||||||||||
| 185 | |||||||||||||||||||||
| 186 | =head2 import | ||||||||||||||||||||
| 187 | |||||||||||||||||||||
| 188 | See L</SYNOPSIS> | ||||||||||||||||||||
| 189 | |||||||||||||||||||||
| 190 | =cut | ||||||||||||||||||||
| 191 | |||||||||||||||||||||
| 192 | #sub import { | ||||||||||||||||||||
| 193 | # my $target = caller; | ||||||||||||||||||||
| 194 | # $_[0]->export_to_level(1, @_); # Symbols | ||||||||||||||||||||
| 195 | # | ||||||||||||||||||||
| 196 | # #$_->import::into($target) foreach qw(strict warnings); # Pragmas | ||||||||||||||||||||
| 197 | # # ... each module has to import those anyway to satisfy Kwalitee. | ||||||||||||||||||||
| 198 | # | ||||||||||||||||||||
| 199 | # #Carp->import::into($target, qw(carp croak confess cluck)); # Packages | ||||||||||||||||||||
| 200 | # #Data::Dumper::Compact->import::into($target, 'ddc'); | ||||||||||||||||||||
| 201 | # #Getargs::Mixed->import::into($target); | ||||||||||||||||||||
| 202 | #} #import() | ||||||||||||||||||||
| 203 | |||||||||||||||||||||
| 204 | 5 | 1; | |||||||||||||||||||
| 205 | __END__ | ||||||||||||||||||||