HTTP2/Trace.pm

filter: Statementstmt 100% 49 / 49 Branchbran 90.0% 9 / 10 Conditioncond 33.3% 1 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 100% 11 / 11 Podpod 0.0% 0 / 2 totaltotal 90.9% 70 / 77 CC 4 SCAR 4.5
CC
4
Cov
95%
bin2hex
3.0
_log
2.0
BEGIN
1.0
CRAP 1.6
« HTTP2/Frame/Goaway.pm ↑ Summary HTTP2.pm »
1 package Protocol::HTTP2::Trace;
2 15 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 15 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 15 ▶use Time::HiRes qw(time);
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 15 ▶use Exporter qw(import);
Subroutine BEGIN: called CC=1 SCAR=0.0
7 15 our @EXPORT_OK = qw(tracer bin2hex);
8  
9 15 my %levels = (
10 debug => 0,
11 info => 1,
12 notice => 2,
13 warning => 3,
14 error => 4,
15 critical => 5,
16 alert => 6,
17 emergency => 7,
18 );
19  
20 my $tracer_sngl = Protocol::HTTP2::Trace->_new(
21 min_level =>
22 ( exists $ENV{HTTP2_DEBUG} && exists $levels{ $ENV{HTTP2_DEBUG} } )
23 ? $levels{ $ENV{HTTP2_DEBUG} }
24 : $levels{error}
25 15 ▶);
Branch: 1 branch
BranchTrueFalseTotal
exists $ENV{'HTTP2_DEBUG'} && exists $levels{$ENV{'HTTP2_DEBUG'}} ? : 0 15 15
Condition33%1/3
exists $ENV{"HTTP2_DEBUG"} and exists $levels{$ENV{"HTTP2_DEBUG"}}
!ll&&!rl&&r
1500
MC/DC0%0/2
exists $ENV{"HTTP2_DEBUG"} and exists $levels{$ENV{"HTTP2_DEBUG"}}
exists $ENV{"HTTP2_DEBUG"} exists $levels{$ENV{"HTTP2_DEBUG"}}
Truth table33%1/3
A and B
A= exists $ENV{"HTTP2_DEBUG"}B= exists $levels{$ENV{"HTTP2_DEBUG"}}
ABresult
0X0
100
111
26 15 my $start_time = 0;
27  
28 28516 ▶sub tracer {
Subroutine tracer: called CC=1 SCAR=0.0
Pod undocumented
29 28516 $tracer_sngl;
30 }
31  
32 15 ▶sub _new {
Subroutine _new: called CC=1 SCAR=0.0
33 15 my ( $class, %opts ) = @_;
34 15 bless {%opts}, $class;
35 }
36  
37 2 ▶sub _log {
Subroutine _log: called CC=2 SCAR=6.9
38 2 my ( $self, $level, $message ) = @_;
39 2 $level = uc($level);
40 2 chomp($message);
41 2 my $now = time;
42 2 ▶ if ( $now - $start_time < 60 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($now - $start_time < 60) { } 1 1 2
43 1 $message =~ s/\n/\n /g;
44 1 printf "[%05.3f] %s %s\n", $now - $start_time, $level, $message;
45 }
46 else {
47 1 my @t = ( localtime() )[ 5, 4, 3, 2, 1, 0 ];
48 1 $t[0] += 1900;
49 1 $t[1]++;
50 1 $message =~ s/\n/\n /g;
51 1 printf "[%4d-%02d-%02d %02d:%02d:%02d] %s %s\n", @t, $level, $message;
52 1 $start_time = $now;
53 }
54 }
55  
56 {
57 15 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
58 15 for my $l ( keys %levels ) {
59 120 *{ __PACKAGE__ . "::" . $l } =
60 ( $levels{$l} >= $tracer_sngl->{min_level} )
61 2 ▶ ? sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
62 2 shift->_log( $l, @_ );
63 }
64 28514 ▶ : sub { 1 }
Subroutine __ANON__: called CC=1 SCAR=0.0
65 120 ▶ }
Branch: 1 branch
BranchTrueFalseTotal
$levels{$l} >= $tracer_sngl->{'min_level'} ? : 60 60 120
66 }
67  
68 1 ▶sub bin2hex {
Subroutine bin2hex: called CC=3 SCAR=11.0
Pod undocumented
69 1 my $bin = shift;
70 1 my $c = 0;
71 1 my $s;
72  
73 join "", map {
74 1 $c++;
75 18 ▶ $s = !( $c % 16 ) ? "\n" : ( $c % 2 ) ? "" : " ";
Branch: 2 branches
BranchTrueFalseTotal
!($c % 16) ? : 1 17 18
$c % 2 ? : 9 8 17
76 18 $_ . $s
77 } unpack( "(H2)*", $bin );
78 }
79  
80 15 1;
« HTTP2/Frame/Goaway.pm ↑ Summary HTTP2.pm »