blib/lib/Log/Any/For/Std.pm

filter: Statementstmt 93.3% 28 / 30 Branchbran 66.6% 4 / 6 Conditioncond 66.6% 6 / 9 MC/DCmcdc 16.6% 1 / 6 Subroutinesub 88.8% 8 / 9 Podpod n/a totaltotal 78.3% 47 / 60 CC 7 SCAR 10.8
CC
7
Cov
84%
PRINT
5.3
__ANON__
3.5
BEGIN
1.0
CRAP 2.9
↑ Summary
1 package Log::Any::For::Std;
2  
3 #
4 # Send output of STDERR to Log::Any
5 #
6  
7 2 ▶use 5.008001;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 2 ▶use Log::Any '$log', default_adapter => 'Duperr';
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13 2 our $VERSION = '0.05';
14  
15 #---
16  
17 2 my $sig;
18  
19 # Value assignment is needed for futher learning in the PRINT method where the message came from
20 0 ▶$SIG{__DIE__} = sub { die @_ if ( $^S or not defined $^S ); $sig = 'DIE' };
Subroutine __ANON__: called CC=3 SCAR=12.5
Branch: 1 branch
BranchTrueFalseTotal
if $^S or not defined $^S 2 0 2
Condition66%2/3
$^S or not defined $^S
l!l&&r!l&&!r
110
MC/DC0%0/2
$^S or not defined $^S
$^S not defined $^S
Truth table66%2/3
A or not(B)
A= $^SB= not defined $^S
ABresult
1X1
011
000
21 1 ▶$SIG{__WARN__} = sub { $sig = 'WARN'; print STDERR @_ };
Subroutine __ANON__: called CC=1 SCAR=0.0
22  
23 # We connect the descriptor STDERR with the current packet for interception of all error messages
24 2 tie *STDERR, __PACKAGE__;
25  
26 # Redefinition of standard constructor for the connnected descriptor STDERR
27 2 ▶sub TIEHANDLE {
Subroutine TIEHANDLE: called CC=1 SCAR=0.0
28 2 my $class = shift;
29  
30 2 bless {}, $class;
31 }
32  
33 # Redefinition of standart method PRINT for the connected descriptor STDERR
34 3 ▶sub PRINT {
Subroutine PRINT: called CC=5 SCAR=16.7
35 3 my ( $self, @msg ) = @_;
36  
37 3 chomp(@msg);
38  
39 # Current value in $@ says where the message came from
40 3 ▶ if ( defined $sig and $sig eq 'DIE' ) {
Branch: 2 branches
BranchTrueFalseTotal
if (defined $sig and $sig eq 'DIE') { } 0 3 3
elsif (defined $sig and $sig eq 'WARN') { } 1 2 3
Condition66%2/3
defined $sig and $sig eq "DIE"
!ll&&!rl&&r
210
MC/DC0%0/2
defined $sig and $sig eq "DIE"
defined $sig $sig eq "DIE"
Truth table66%2/3
A and B
A= defined $sigB= $sig eq "DIE"
ABresult
0X0
100
111
41 0 $log->emergency(@msg);
42 }
43 ▶ elsif ( defined $sig and $sig eq 'WARN' ) {
Condition66%2/3
defined $sig and $sig eq "WARN"
!ll&&!rl&&r
201
MC/DC50%1/2
defined $sig and $sig eq "WARN"
defined $sig $sig eq "WARN"
Truth table66%2/3
A and B
A= defined $sigB= $sig eq "WARN"
ABresult
0X0
100
111
44 1 $log->warning(@msg);
45 }
46 else {
47 2 $log->notice(@msg);
48 }
49  
50 # Reset to the default value
51 3 undef $sig;
52 }
53  
54 # Redefinition of standard methode BINMODE for the connected descriptor STDERR
55 # In fact this method makes no sense here but it has to be fulfiled for the backward compatibility
56 # with the modules that call this method for their own purposes
57 0 ▶sub BINMODE { }
Subroutine BINMODE: not called CC=1 SCAR=0.0
58  
59 2 1;
60  
61 __END__
↑ Summary