blib/lib/Log/Dispatch/Config/TestLog.pm

filter: Statementstmt 87.1% 54 / 62 Branchbran 33.3% 6 / 18 Conditioncond 41.6% 5 / 12 MC/DCmcdc 0.0% 0 / 6 Subroutinesub 87.5% 14 / 16 Podpod 0.0% 0 / 5 totaltotal 66.3% 79 / 119 CC 16 SCAR 17.4
CC
16
Cov
71%
__ANON__
12.0
caller_file_to_log_file
11.2
import
8.0
CRAP 5.7
↑ Summary
1 #!/usr/bin/perl
2  
3 package Log::Dispatch::Config::TestLog;
4  
5 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 2 our $VERSION = "0.02";
9  
10 2 ▶use Sub::Override;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 2 ▶use Test::Builder;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 2 ▶use Log::Dispatch::Config;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 2 ▶use Path::Class;
Subroutine BEGIN: called CC=1 SCAR=0.0
14  
15 2 ▶use base qw(Log::Dispatch::Configurator);
Subroutine BEGIN: called CC=1 SCAR=0.0
16  
17 1 ▶sub new {
Subroutine new: called CC=3 SCAR=11.4
Pod undocumented
18 1 my ( $class, %args ) = @_;
19  
20 bless {
21 %args,
22 global => {
23 dispatchers => [qw(file)],
24 1 ▶ %{ $args{global} || {} }
Condition50%1/2
$args{'global'} || {}
l!l
01
MC/DC0%0/1
$args{'global'} || {}
$args{'global'}
Truth table50%1/2
A
A= $args{'global'}
Aresult
11
00
25 },
26 file => {
27 class => 'Log::Dispatch::File',
28 min_level => 'debug',
29 1 ▶ %{ $args{file} || {} }
Condition50%1/2
$args{'file'} || {}
l!l
10
MC/DC0%0/1
$args{'file'} || {}
$args{'file'}
Truth table50%1/2
A
A= $args{'file'}
Aresult
11
00
30 },
31 }, $class;
32 }
33  
34 2 ▶sub get_attrs {
Subroutine get_attrs: called CC=1 SCAR=0.0
Pod undocumented
35 2 my ( $self, $name ) = @_;
36 2 $self->{$name};
37 }
38  
39 1 ▶sub get_attrs_global { shift->get_attrs("global") }
Subroutine get_attrs_global: called CC=1 SCAR=0.0
Pod undocumented
40  
41 0 ▶sub needs_reload { return }
Subroutine needs_reload: not called CC=1 SCAR=6.9
Pod undocumented
42  
43 1 ▶sub caller_file_to_log_file {
Subroutine caller_file_to_log_file: called CC=6 SCAR=24.2
Pod undocumented
44 1 my ( $self, $file, %args ) = @_;
45  
46 1 ▶ my $log_dir = dir( $ENV{TEST_LOG_DIR} || $args{log_dir} || $file->parent );
Condition33%2/6
$ENV{'TEST_LOG_DIR'} || $args{'log_dir'} || $file->parent
l!l&&r!l&&!r
010
$ENV{"TEST_LOG_DIR"} or $args{"log_dir"}
l!l&&r!l&&!r
001
MC/DC0%0/3
$ENV{'TEST_LOG_DIR'} || $args{'log_dir'} || $file->parent
$ENV{"TEST_LOG_DIR"} $args{"log_dir"} $file->parent
Truth table25%1/4
A or B || C
A= $ENV{"TEST_LOG_DIR"}B= $args{"log_dir"}C= $file->parent
ABCresult
1XX1
01X1
0011
0000
47  
48 1 ▶ unless ( -d $log_dir ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (-d $log_dir) 0 1 1
49 0 ▶ $log_dir->mkpath
Branch: 1 branch
BranchTrueFalseTotal
$log_dir->mkpath or die "Couldn't create test log directory $log_dir" 0 0 0
50 or die "Couldn't create test log directory $log_dir";
51 }
52  
53 1 ▶ unless ( -w $log_dir ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (-w $log_dir) 0 1 1
54 0 die "Log directory $log_dir is not writable";
55 }
56  
57 1 return $log_dir->file( $file->basename . ".log" )->stringify;
58 }
59  
60 2 my @overrides;
61  
62 1 ▶sub import {
Subroutine import: called CC=6 SCAR=20.8
63 1 my ( $self, %args ) = @_;
64  
65 1 require Test::Builder;
66  
67 1 my $file = file($0)->absolute;
68  
69 Log::Dispatch::Config->configure(
70 $self->new(
71 %args,
72 file => {
73 mode => "write",
74 filename => $self->caller_file_to_log_file( $file, %args ),
75 format => "[%d] [%p] %m\n",
76 1 ▶ %{ $args{file} || {} }
Condition50%1/2
$args{'file'} || {}
l!l
10
MC/DC0%0/1
$args{'file'} || {}
$args{'file'}
Truth table50%1/2
A
A= $args{'file'}
Aresult
11
00
77 },
78 ),
79 );
80  
81 1 my $logger = Log::Dispatch::Config->instance;
82  
83 1 $logger->info("Starting test $0, pid = $$");
84  
85 my $tap_level = exists($args{tap_log_level})
86 ? $args{tap_log_level}
87 1 ▶ : "info";
Branch: 1 branch
BranchTrueFalseTotal
exists $args{'tap_log_level'} ? : 0 1 1
88  
89 1 ▶ if ( defined( $tap_level ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $tap_level) 1 0 1
90
91 1 ▶ unless ( @overrides ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (@overrides) 1 0 1
92 1 foreach my $print ( qw(_diag _print_to_fh) ) {
93 2 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
94 2 my $fq = "Test::Builder::$print";
95 2 my $orig = \&$fq;
96  
97 0 ▶ push @overrides, Sub::Override->new( $fq, sub {
Subroutine __ANON__: not called CC=3 SCAR=24.8
98 0 my ( $builder, @output ) = @_;
99 0 ▶ shift @output if $print eq '_print_to_fh'; # first arg is output handle
Branch: 1 branch
BranchTrueFalseTotal
if $print eq "_print_to_fh" 0 0 0
100 0 chomp( my $out = "@output" );
101 0 ▶ $logger->$tap_level("TAP: $out") if length $out;
Branch: 1 branch
BranchTrueFalseTotal
if length $out 0 0 0
102 0 goto $orig;
103 2 });
104 }
105 }
106 }
107 }
108  
109 1 ▶END {
Subroutine END: called CC=2 SCAR=7.6
110 1 ▶ Log::Dispatch::Config->__instance && Log::Dispatch::Config->instance->info("Finishing test $0");
Branch: 1 branch
BranchTrueFalseTotal
"Log::Dispatch::Config"->__instance and "Log::Dispatch::Config"->instance->info("Finishing test $0") 1 0 1
111 }
112  
113 2 __PACKAGE__
114  
115 __END__
↑ Summary