| 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
Condition66%2/3
$^S or not defined $^S
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
| |||||||||||||||||||||||||||||||||
| 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
Condition66%2/3
defined $sig and $sig eq "DIE"
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"
| |||||||||||||||||||||||||||||||||
| 41 | 0 | $log->emergency(@msg); | |||||||||||||||||||||||||||||||
| 42 | } | ||||||||||||||||||||||||||||||||
| 43 | ▶ | elsif ( defined $sig and $sig eq 'WARN' ) { | |||||||||||||||||||||||||||||||
|
Condition66%2/3
defined $sig and $sig eq "WARN"
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"
| |||||||||||||||||||||||||||||||||
| 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__ | ||||||||||||||||||||||||||||||||