blib/lib/Perinci/CmdLine/Plugin/Run/DebugCompletion.pm

filter: Statementstmt 51.5% 17 / 33 Branchbran 0.0% 0 / 4 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 66.6% 4 / 6 Podpod 0.0% 0 / 2 totaltotal 46.6% 21 / 45 CC 3 SCAR 16.6
CC
3
Cov
46%
on_run
12.0
meta
2.0
BEGIN
1.0
CRAP 5.2
« blib/lib/Perinci/CmdLine/Plugin/Run/DumpObject.pm ↑ Summary blib/lib/Perinci/CmdLine/Plugin/Debug/DumpArgs.pm »
1 package Perinci::CmdLine::Plugin::Run::DebugCompletion;
2  
3 # put pragmas + Log::ger here
4 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 1 ▶use Log::ger;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 1 ▶use parent 'Perinci::CmdLine::PluginBase';
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 # put other modules alphabetically here
10  
11 # put global variables alphabetically here
12 1 our $AUTHORITY = 'cpan:PERLANCAR'; # AUTHORITY
13 1 our $DATE = '2023-11-23'; # DATE
14 1 our $DIST = 'Perinci-CmdLine-Lite'; # DIST
15 1 our $VERSION = '1.929'; # VERSION
16  
17 0 ▶sub meta {
Subroutine meta: not called CC=1 SCAR=6.9
Pod undocumented
18 return {
19 0 summary => 'Debug completion',
20 description => <<'_',
21  
22 This plugin will make your script log tab completion information to a log file
23 then exit instead of doing a normal run. It can be used to debug tab completion
24 issues. An example of log line it produces:
25  
26 [/path/to/your-script] [prog PROGNAME] [pid 12345] [uid 1000] COMP_LINE=<your-script > (%d char(s)) COMP_POINT=<%s>\n",
27  
28 This plugin is not included by default. To activate this plugin from the
29 command-line of bash shell:
30  
31 % PERINCI_CMDLINE_PLUGINS="-Run::DebugCompletion" your-script ...
32  
33 By default it logs to `/tmp/pericmd-completion.log`. To customize the log file
34 location:
35  
36 % PERINCI_CMDLINE_PLUGINS="-Run::DebugCompletion,log_file,/path/to/log.file" your-script ...
37  
38 This plugin runs at the C<run> event at a very high priority (1) then skips
39 all the other run handlers (return 201 status).
40  
41 _
42 conf => {
43 log_file => {
44 summary => 'Location of log file',
45 schema => 'filename*',
46 description => <<'_',
47  
48 If not specified, will use `/tmp/pericmd-completion.log`.
49  
50 _
51 },
52 },
53 prio => 1, # very high
54 tags => ['category:run-handler', 'category:debugging'],
55 };
56 }
57  
58 0 ▶sub on_run {
Subroutine on_run: not called CC=3 SCAR=24.8
Pod undocumented
59 0 my ($self, $r) = @_;
60  
61 0 my $log_file = $self->{log_file};
62 0 ▶ unless (defined $log_file) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $log_file) 0 0 0
63 0 require File::Spec;
64 0 my $tmpdir = File::Spec->tmpdir;
65 0 $log_file = File::Spec->catfile($tmpdir, "pericmd-completion.log");
66 }
67  
68 LOG: {
69 0 open my $fh, ">>", $log_file
70 0 ▶ or do { warn "Can't open completion log file, skipped: $!"; last };
Branch: 1 branch
BranchTrueFalseTotal
open my $fh, ">>", $log_file or do { warn "Can't open completion log file, skipped: $!"; last } 0 0 0
71 print $fh sprintf(
72 "[%s] [prog %s] [pid %d] [uid %d] COMP_LINE=<%s> (%d char(s)) COMP_POINT=<%s>\n",
73 scalar(localtime),
74 $0,
75 $$,
76 $>,
77 $ENV{COMP_LINE},
78 length($ENV{COMP_LINE}),
79 $ENV{COMP_POINT},
80 0 );
81 0 print $fh join("", map {" $_=$ENV{$_}\n"} sort keys %ENV);
82 0 close $fh;
83 }
84  
85 0 [201, "OK"]; # skip the rest of the event handlers
86 }
87  
88 1 1;
89 # ABSTRACT: Debug completion
90  
91 __END__
« blib/lib/Perinci/CmdLine/Plugin/Run/DumpObject.pm ↑ Summary blib/lib/Perinci/CmdLine/Plugin/Debug/DumpArgs.pm »