Spore/Role/Debug.pm

filter: Statementstmt 85.7% 30 / 35 Branchbran 56.2% 9 / 16 Conditioncond 0.0% 0 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 80.0% 4 / 5 Podpod 0.0% 0 / 1 totaltotal 69.3% 43 / 62 CC 10 SCAR 19.2
CC
10
Cov
72%
_trace_verbose
12.0
BUILD
7.7
_trace_msg
2.0
CRAP 6.8
« Spore/Request.pm ↑ Summary Spore/Middleware/LogDispatch.pm »
1 package Net::HTTP::Spore::Role::Debug;
2 26 $Net::HTTP::Spore::Role::Debug::VERSION = '0.09';
3 26 ▶use IO::File;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 26 ▶use Moose::Role;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 26 has trace => (
7 is => 'rw',
8 isa => 'Str',
9 predicate => 'has_trace',
10 clearer => 'reset_trace',
11 );
12  
13 26 has _trace_fh => (
14 is => 'rw',
15 isa => 'GLOB',
16 );
17  
18 33 ▶sub BUILD {
Subroutine BUILD: called CC=7 SCAR=20.4
Pod undocumented
19 33 my ($self, $args) = @_;
20 33 my $trace;
21  
22 33 ▶ $trace = $args->{trace} if $args->{trace};
Branch: 1 branch
BranchTrueFalseTotal
if $args->{"trace"} 1 32 33
23 33 ▶ $trace = $ENV{SPORE_TRACE} if defined $ENV{SPORE_TRACE};
Branch: 1 branch
BranchTrueFalseTotal
if defined $ENV{"SPORE_TRACE"} 0 33 33
24  
25 33 ▶ if (!defined $trace){
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $trace) 32 1 33
26 32 $self->reset_trace;
27 32 return;
28 }
29  
30 1 my ($level, $fh);
31 1 ▶ if ( $trace =~ /(\d)=(.+)$/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($trace =~ /(\d)=(.+)$/) { } 1 0 1
32 1 $level = $1;
33 1 my $file = $2;
34 1 ▶ $fh = IO::File->new( $file, 'w' )
Branch: 1 branch
BranchTrueFalseTotal
$fh = "IO::File"->new($file, "w") or die "Cannot open trace file $file" 1 0 1
35 or die "Cannot open trace file $file";
36 }
37 else {
38 0 $level = $trace;
39 0 ▶ $fh = IO::File->new('>&STDERR')
Branch: 1 branch
BranchTrueFalseTotal
$fh = "IO::File"->new(">&STDERR") or die "Duplication of STDERR for debug output failed (perhaps your STDERR is closed?)" 0 0 0
40 or die('Duplication of STDERR for debug output failed (perhaps your STDERR is closed?)');
41 }
42 1 $fh->autoflush;
43 1 $self->_trace_fh($fh);
44 1 $self->trace($level);
45 }
46  
47 41 ▶sub _trace_msg {
Subroutine _trace_msg: called CC=2 SCAR=6.9
48 41 my $self = shift;
49 41 my $template = shift;
50 41 ▶ return unless $self->has_trace;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->has_trace 40 1 41
51  
52 1 my $fh = $self->_trace_fh();
53 1 print $fh (sprintf( $template, @_ )."\n");
54 }
55  
56 0 ▶sub _trace_verbose {
Subroutine _trace_verbose: not called CC=3 SCAR=24.8
57 0 my $self = shift;
58 0 ▶ return unless $self->trace && $self->trace > 1;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->trace and $self->trace > 1 0 0 0
Condition0%0/3
$self->trace and $self->trace > 1
!ll&&!rl&&r
000
MC/DC0%0/2
$self->trace and $self->trace > 1
$self->trace $self->trace > 1
Truth table0%0/3
A and B
A= $self->traceB= $self->trace > 1
ABresult
0X0
100
111
59 0 $self->_trace_msg(@_);
60 }
61  
62 26 1;
63  
64 __END__
« Spore/Request.pm ↑ Summary Spore/Middleware/LogDispatch.pm »