| 1 | =head1 NAME | ||||||||||||||
| 2 | |||||||||||||||
| 3 | debug - Greple module for debug control | ||||||||||||||
| 4 | |||||||||||||||
| 5 | =head1 SYNOPSIS | ||||||||||||||
| 6 | |||||||||||||||
| 7 | greple -dmc | ||||||||||||||
| 8 | |||||||||||||||
| 9 | greple -Mdebug | ||||||||||||||
| 10 | |||||||||||||||
| 11 | greple -Mdebug::on(getoptex) | ||||||||||||||
| 12 | |||||||||||||||
| 13 | greple -Mdebug::on=getoptex | ||||||||||||||
| 14 | |||||||||||||||
| 15 | =head1 DESCRIPTION | ||||||||||||||
| 16 | |||||||||||||||
| 17 | Enable debug mode for specified target. Currently, following targets | ||||||||||||||
| 18 | are available. | ||||||||||||||
| 19 | |||||||||||||||
| 20 | getoptex Getopt::EX | ||||||||||||||
| 21 | getopt Getopt::Long | ||||||||||||||
| 22 | alert -da Alert information | ||||||||||||||
| 23 | color -dc Color information | ||||||||||||||
| 24 | directory -dd Change directory information | ||||||||||||||
| 25 | file -df Show search file names | ||||||||||||||
| 26 | number -dn Show number of processing files | ||||||||||||||
| 27 | match -dm Match pattern | ||||||||||||||
| 28 | option -do Show command option processing | ||||||||||||||
| 29 | process -dp Exec ps command before exit | ||||||||||||||
| 30 | stat -ds Show statistic information | ||||||||||||||
| 31 | grep -dg Show grep internal state | ||||||||||||||
| 32 | filter -dF Show filter informaiton | ||||||||||||||
| 33 | unused -du Show unused 1-char option name | ||||||||||||||
| 34 | |||||||||||||||
| 35 | When used without function call, default target is enabled; currently | ||||||||||||||
| 36 | C<getoptex> and C<option>. | ||||||||||||||
| 37 | |||||||||||||||
| 38 | $ greple -Mdebug | ||||||||||||||
| 39 | |||||||||||||||
| 40 | Specify required target with C<on> function like: | ||||||||||||||
| 41 | |||||||||||||||
| 42 | $ greple -Mdebug::on(color,match,option) | ||||||||||||||
| 43 | |||||||||||||||
| 44 | $ greple -Mdebug::on=color,match,option | ||||||||||||||
| 45 | |||||||||||||||
| 46 | Calling C<debug::on=all> enables all targets, except C<unused> and | ||||||||||||||
| 47 | C<number>. | ||||||||||||||
| 48 | |||||||||||||||
| 49 | Target name marked with C<-dx> can be enabled in that form. Following | ||||||||||||||
| 50 | commands are all equivalent. | ||||||||||||||
| 51 | |||||||||||||||
| 52 | $ greple -Mdebug::on=color,match,option | ||||||||||||||
| 53 | |||||||||||||||
| 54 | $ greple -dc -dm -do | ||||||||||||||
| 55 | |||||||||||||||
| 56 | $ greple -dcmo | ||||||||||||||
| 57 | |||||||||||||||
| 58 | =head1 EXAMPLE | ||||||||||||||
| 59 | |||||||||||||||
| 60 | Next command will show how the module option is processed in | ||||||||||||||
| 61 | L<Getopt::EX> module. | ||||||||||||||
| 62 | |||||||||||||||
| 63 | $ greple -Mdebug::on=getoptex,option -Mdig something --dig . | ||||||||||||||
| 64 | |||||||||||||||
| 65 | =cut | ||||||||||||||
| 66 | |||||||||||||||
| 67 | |||||||||||||||
| 68 | package App::Greple::debug; | ||||||||||||||
| 69 | |||||||||||||||
| 70 | 1 | ▶ | use v5.24; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 71 | 1 | ▶ | use warnings; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 72 | 1 | ▶ | use Carp; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 73 | 1 | ▶ | use Data::Dumper; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 74 | |||||||||||||||
| 75 | 1 | ▶ | use App::Greple::Common qw(%debug &FILELABEL); | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 76 | 1 | ▶ | use Getopt::Long; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 77 | |||||||||||||||
| 78 | my %flags = ( | ||||||||||||||
| 79 | getoptex => \$Getopt::EX::Loader::debug, | ||||||||||||||
| 80 | 0 | ▶ | getopt => { on => sub { main::configure_getopt('debug') }, | ||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||
| 81 | 0 | ▶ | off => sub { main::configure_getopt('no_debug') } }, | ||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||
| 82 | alert => \$debug{a}, | ||||||||||||||
| 83 | color => \$debug{c}, | ||||||||||||||
| 84 | directory => \$debug{d}, | ||||||||||||||
| 85 | file => \$debug{f}, | ||||||||||||||
| 86 | number => \$debug{n}, | ||||||||||||||
| 87 | match => \$debug{m}, | ||||||||||||||
| 88 | misc => \$debug{m}, | ||||||||||||||
| 89 | option => \$debug{o}, | ||||||||||||||
| 90 | process => \$debug{p}, | ||||||||||||||
| 91 | stat => \$debug{s}, | ||||||||||||||
| 92 | grep => \$debug{g}, | ||||||||||||||
| 93 | filter => \$debug{F}, | ||||||||||||||
| 94 | unused => \$debug{u}, | ||||||||||||||
| 95 | 1 | ); | |||||||||||||
| 96 | |||||||||||||||
| 97 | 0 | ▶ | sub getoptex { on ( getoptex => 1 ) } | ||||||||||||
|
Subroutine
getoptex: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||
| 98 | 0 | ▶ | sub getopt { on ( getopt => 1 ) } | ||||||||||||
|
Subroutine
getopt: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||
| 99 | 0 | ▶ | sub alert { on ( alert => 1 ) } | ||||||||||||
|
Subroutine
alert: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||
| 100 | 0 | ▶ | sub color { on ( color => 1 ) } | ||||||||||||
|
Subroutine
color: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||
| 101 | 0 | ▶ | sub directory { on ( directory => 1 ) } | ||||||||||||
|
Subroutine
directory: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||
| 102 | 0 | ▶ | sub file { on ( file => 1 ) } | ||||||||||||
|
Subroutine
file: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||
| 103 | 0 | ▶ | sub number { on ( number => 1 ) } | ||||||||||||
|
Subroutine
number: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||
| 104 | 0 | ▶ | sub match { on ( match => 1 ) } | ||||||||||||
|
Subroutine
match: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||
| 105 | 0 | ▶ | sub misc { on ( match => 1 ) } | ||||||||||||
|
Subroutine
misc: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||
| 106 | 0 | ▶ | sub option { on ( option => 1 ) } | ||||||||||||
|
Subroutine
option: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||
| 107 | 0 | ▶ | sub process { on ( process => 1 ) } | ||||||||||||
|
Subroutine
process: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||
| 108 | 0 | ▶ | sub stat { on ( stat => 1 ) } | ||||||||||||
|
Subroutine
stat: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||
| 109 | 0 | ▶ | sub grep { on ( grep => 1 ) } | ||||||||||||
|
Subroutine
grep: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||
| 110 | 0 | ▶ | sub filter { on ( filter => 1 ) } | ||||||||||||
|
Subroutine
filter: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||
| 111 | 0 | ▶ | sub unused { on ( unused => 1 ) } | ||||||||||||
|
Subroutine
unused: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||
| 112 | |||||||||||||||
| 113 | 1 | my %exclude = map { $_ => 1 } qw(unused number); | |||||||||||||
| 114 | |||||||||||||||
| 115 | 1 | my @all_flags = grep { not $exclude{$_} } sort keys %flags; | |||||||||||||
| 116 | |||||||||||||||
| 117 | 0 | ▶ | sub switch { | ||||||||||||
|
Subroutine
switch: not called CC=8 SCAR=42.8
Pod
undocumented
| |||||||||||||||
| 118 | 0 | my %arg = @_; | |||||||||||||
| 119 | 0 | my @keys = keys %arg; | |||||||||||||
| 120 | 0 | ▶ | while (@keys) { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 121 | 0 | my $key = shift @keys; | |||||||||||||
| 122 | 0 | my $val = $arg{$key}; | |||||||||||||
| 123 | 0 | ▶ | my $e = $flags{$key} or next; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 124 | 0 | ▶ | if (ref $e eq 'ARRAY') { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 125 | 0 | unshift @keys, @{$e}; | |||||||||||||
| 126 | 0 | next; | |||||||||||||
| 127 | } | ||||||||||||||
| 128 | 0 | ▶ | if (ref $e eq 'HASH') { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 129 | 0 | ▶ | if (my $sub = $e->{ $val ? 'on' : 'off' }) { | ||||||||||||
|
Branch: 2 branches
| |||||||||||||||
| 130 | 0 | ▶ | ref $sub eq 'CODE' or die; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 131 | 0 | $sub->(); | |||||||||||||
| 132 | } | ||||||||||||||
| 133 | } else { | ||||||||||||||
| 134 | 0 | ${$e} = $val; | |||||||||||||
| 135 | } | ||||||||||||||
| 136 | } | ||||||||||||||
| 137 | } | ||||||||||||||
| 138 | |||||||||||||||
| 139 | 1 | my @default = qw(getoptex option); | |||||||||||||
| 140 | |||||||||||||||
| 141 | 0 | ▶ | sub switch_default { | ||||||||||||
|
Subroutine
switch_default: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||
| 142 | 0 | switch map { $_ => $_[0] } @default; | |||||||||||||
| 143 | } | ||||||||||||||
| 144 | |||||||||||||||
| 145 | 0 | ▶ | sub on { | ||||||||||||
|
Subroutine
on: not called CC=3 SCAR=24.8
Pod
undocumented
| |||||||||||||||
| 146 | 0 | my %arg = @_; | |||||||||||||
| 147 | 0 | delete $arg{&FILELABEL}; # no entry when called from -M otption. | |||||||||||||
| 148 | |||||||||||||||
| 149 | # Clear default setting on first call. | ||||||||||||||
| 150 | 0 | state $called; | |||||||||||||
| 151 | 0 | ▶ | $called++ or switch_default 0; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 152 | |||||||||||||||
| 153 | 0 | ▶ | if (delete $arg{'all'}) { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 154 | 0 | map { $arg{$_} = 1 } @all_flags; | |||||||||||||
| 155 | } | ||||||||||||||
| 156 | |||||||||||||||
| 157 | 0 | switch(%arg); | |||||||||||||
| 158 | } | ||||||||||||||
| 159 | |||||||||||||||
| 160 | 0 | ▶ | sub initialize { | ||||||||||||
|
Subroutine
initialize: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||
| 161 | 0 | switch_default 1; | |||||||||||||
| 162 | } | ||||||||||||||
| 163 | |||||||||||||||
| 164 | 1 | 1; | |||||||||||||
| 165 | |||||||||||||||
| 166 | # LocalWords: getoptex getopt grep greple misc | ||||||||||||||