blib/lib/IO/Async/Debug.pm

filter: Statementstmt 37.9% 11 / 29 Branchbran 0.0% 0 / 8 Conditioncond 22.2% 2 / 9 MC/DCmcdc 0.0% 0 / 5 Subroutinesub 50.0% 2 / 4 Podpod 0.0% 0 / 2 totaltotal 26.3% 15 / 57 CC 8 SCAR 36.1
CC
8
Cov
28%
logf
56.0
log_hexdump
6.0
BEGIN
1.0
CRAP 36.9
« blib/lib/IO/Async/Internals/ChildManager.pm ↑ Summary blib/lib/IO/Async/Internals/Connector.pm »
1 # You may distribute under the terms of either the GNU General Public License
2 # or the Artistic License (the same terms as Perl itself)
3 #
4 # (C) Paul Evans, 2015-2024 -- leonerd@leonerd.org.uk
5  
6 package IO::Async::Debug 0.805;
7  
8 84 ▶use v5.14;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 84 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 84 ▶our $DEBUG = $ENV{IO_ASYNC_DEBUG} || 0;
Condition50%1/2
$ENV{'IO_ASYNC_DEBUG'} || 0
l!l
084
MC/DC0%0/1
$ENV{'IO_ASYNC_DEBUG'} || 0
$ENV{'IO_ASYNC_DEBUG'}
Truth table50%1/2
A
A= $ENV{'IO_ASYNC_DEBUG'}
Aresult
11
00
12 84 our $DEBUG_FD = $ENV{IO_ASYNC_DEBUG_FD};
13 84 our $DEBUG_FILE = $ENV{IO_ASYNC_DEBUG_FILE};
14 84 our $DEBUG_FH;
15 84 ▶our %DEBUG_FLAGS = map { $_ => 1 } split m/,/, $ENV{IO_ASYNC_DEBUG_FLAGS} || "";
Condition50%1/2
$ENV{'IO_ASYNC_DEBUG_FLAGS'} || ''
l!l
084
MC/DC0%0/1
$ENV{'IO_ASYNC_DEBUG_FLAGS'} || ''
$ENV{'IO_ASYNC_DEBUG_FLAGS'}
Truth table50%1/2
A
A= $ENV{'IO_ASYNC_DEBUG_FLAGS'}
Aresult
11
00
16  
17 =head1 NAME
18  
19 C<IO::Async::Debug> - debugging control and support for L<IO::Async>
20  
21 =head1 DESCRIPTION
22  
23 The following methods and behaviours are still experimental and may change or
24 even be removed in future.
25  
26 Debugging support is enabled by an environment variable called
27 C<IO_ASYNC_DEBUG> having a true value.
28  
29 When debugging is enabled, the C<make_event_cb> and C<invoke_event> methods
30 on L<IO::Async::Notifier> (and their C<maybe_> variants) are altered such that
31 when the event is fired, a debugging line is printed, using the C<debug_printf>
32 method. This identifes the name of the event.
33  
34 By default, the line is only printed if the caller of one of these methods is
35 the same package as the object is blessed into, allowing it to print the
36 events of the most-derived class, without the extra verbosity of the
37 lower-level events of its parent class used to create it. All calls regardless
38 of caller can be printed by setting a number greater than 1 as the value of
39 C<IO_ASYNC_DEBUG>.
40  
41 By default the debugging log goes to C<STDERR>, but two other environment
42 variables can redirect it. If C<IO_ASYNC_DEBUG_FILE> is set, it names a file
43 which will be opened for writing, and logging written into it. Otherwise, if
44 C<IO_ASYNC_DEBUG_FD> is set, it gives a file descriptor number that logging
45 should be written to. If opening the named file or file descriptor fails then
46 the log will be written to C<STDERR> as normal.
47  
48 Extra debugging flags can be set in a comma-separated list in an environment
49 variable called C<IO_ASYNC_DEBUG_FLAGS>. The presence of these flags can cause
50 extra information to be written to the log. Full details on these flags will
51 be documented by the implementing classes. Typically these flags take the form
52 of one or more capital letters indicating the class, followed by one or more
53 lowercase letters enabling some particular feature within that class.
54  
55 =cut
56  
57 sub logf
58 {
59 0 ▶ my ( $fmt, @args ) = @_;
Subroutine logf: not called CC=7 SCAR=40.3
Pod undocumented
60  
61 0 ▶ $DEBUG_FH ||= do {
Condition0%0/3
$IO::Async::Debug::DEBUG_FH ||= do { my $fh; if ($IO::Async::Debug::DEBUG_FILE) { open $fh, ">", $IO::Async::Debug::DEBUG_FILE or undef $fh; } elsif ($IO::Async::Debug::DEBUG_FD) { $fh = "IO::Handle"->new; $fh->fdopen($IO::Async::Debug::DEBUG_FD, "w") or undef $fh; } ; $fh ||= \*STDERR; $fh->autoflush; $fh }
l!l&&r!l&&!r
000
MC/DC0%0/2
$IO::Async::Debug::DEBUG_FH ||= do { my $fh; if ($IO::Async::Debug::DEBUG_FILE) { open $fh, ">", $IO::Async::Debug::DEBUG_FILE or undef $fh; } elsif ($IO::Async::Debug::DEBUG_FD) { $fh = "IO::Handle"->new; $fh->fdopen($IO::Async::Debug::DEBUG_FD, "w") or undef $fh; } ; $fh ||= \*STDERR; $fh->autoflush; $fh }
$IO::Async::Debug::DEBUG_FH do { my $fh; if ($IO::Async::Debug::DEBUG_FILE) { open $fh, ">", $IO::Async::Debug::DEBUG_FILE or undef $fh; } elsif ($IO::Async::Debug::DEBUG_FD) { $fh = "IO::Handle"->new; $fh->fdopen($IO::Async::Debug::DEBUG_FD, "w") or undef $fh; } ; $fh ||= \*STDERR; $fh->autoflush; $fh }
Truth table0%0/3
A ||= B
A= $IO::Async::Debug::DEBUG_FHB= do { my $fh; if ($IO::Async::Debug::DEBUG_FILE) { open $fh, ">", $IO::Async::Debug::DEBUG_FILE or undef $fh; } elsif ($IO::Async::Debug::DEBUG_FD) { $fh = "IO::Handle"->new; $fh->fdopen($IO::Async::Debug::DEBUG_FD, "w") or undef $fh; } ; $fh ||= \*STDERR; $fh->autoflush; $fh }
ABresult
1X1
011
000
62 0 my $fh;
63 0 ▶ if( $DEBUG_FILE ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($IO::Async::Debug::DEBUG_FILE) { } 0 0 0
elsif ($IO::Async::Debug::DEBUG_FD) { } 0 0 0
64 0 ▶ open $fh, ">", $DEBUG_FILE or undef $fh;
Branch: 1 branch
BranchTrueFalseTotal
open $fh, ">", $IO::Async::Debug::DEBUG_FILE or undef $fh 0 0 0
65 }
66 elsif( $DEBUG_FD ) {
67 0 $fh = IO::Handle->new;
68 0 ▶ $fh->fdopen( $DEBUG_FD, "w" ) or undef $fh;
Branch: 1 branch
BranchTrueFalseTotal
$fh->fdopen($IO::Async::Debug::DEBUG_FD, "w") or undef $fh 0 0 0
69 }
70 0 ▶ $fh ||= \*STDERR;
Condition0%0/2
$fh ||= \*STDERR
l!l
00
MC/DC0%0/1
$fh ||= \*STDERR
$fh
Truth table0%0/2
A
A= $fh
Aresult
11
00
71 0 $fh->autoflush;
72 0 $fh;
73 };
74  
75 0 printf $DEBUG_FH $fmt, @args;
76 }
77  
78 sub log_hexdump
79 {
80 0 ▶ my ( $bytes ) = @_;
Subroutine log_hexdump: not called CC=2 SCAR=17.9
Pod undocumented
81  
82 0 foreach my $chunk ( $bytes =~ m/(.{1,16})/sg ) {
83 0 my $chunk_hex = join " ", map { sprintf "%02X", ord $_ } split //, $chunk;
84 0 ( my $chunk_safe = $chunk ) =~ s/[^\x20-\x7e]/./g;
85  
86 0 logf " | %-48s | %-16s |\n", $chunk_hex, $chunk_safe;
87 }
88 }
89  
90 =head1 AUTHOR
91  
92 Paul Evans <leonerd@leonerd.org.uk>
93  
94 =cut
95  
96 84 0x55AA;
« blib/lib/IO/Async/Internals/ChildManager.pm ↑ Summary blib/lib/IO/Async/Internals/Connector.pm »