Log/Report/Dispatcher/Try.pm

filter: Statementstmt 95.5% 64 / 67 Branchbran 72.2% 13 / 18 Conditioncond 61.5% 16 / 26 MC/DCmcdc 30.7% 4 / 13 Subroutinesub 90.9% 20 / 22 Podpod 92.3% 12 / 13 totaltotal 81.1% 129 / 159 CC 22 SCAR 14.2
CC
22
Cov
84%
log
8.8
wasFatal
6.3
reportFatal
6.0
CRAP 4.1
« Log/Report/Dispatcher/Log4perl.pm ↑ Summary Log/Report/Exception.pm »
1 # This code is part of Perl distribution Log-Report version 1.46.
2 # The POD got stripped from this file by OODoc version 3.06.
3 # For contributors see file ChangeLog.
4  
5 # This software is copyright (c) 2007-2026 by Mark Overmeer.
6  
7 # This is free software; you can redistribute it and/or modify it under
8 # the same terms as the Perl 5 programming language system itself.
9 # SPDX-License-Identifier: Artistic-1.0-Perl OR GPL-1.0-or-later
10  
11  
12 package Log::Report::Dispatcher::Try;{
13 17 our $VERSION = '1.46';
14 }
15  
16 17 ▶use base 'Log::Report::Dispatcher';
Subroutine BEGIN: called CC=1 SCAR=0.0
17  
18 17 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
19 17 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
20  
21 17 ▶use Log::Report 'log-report', import => [ qw/__x error/ ];
Subroutine BEGIN: called CC=1 SCAR=0.0
22  
23 17 ▶use Log::Report::Exception ();
Subroutine BEGIN: called CC=1 SCAR=0.0
24 17 ▶use Log::Report::Util qw/%reason_code expand_reasons/;
Subroutine BEGIN: called CC=1 SCAR=0.0
25 17 ▶use List::Util qw/first/;
Subroutine BEGIN: called CC=1 SCAR=0.0
26  
27 #--------------------
28  
29 use overload
30 17 ▶ bool => 'failed',
Subroutine BEGIN: called CC=1 SCAR=0.0
31 '""' => 'showStatus',
32 17 fallback => 1;
33  
34 #--------------------
35  
36 sub init($)
37 21 ▶{ my ($self, $args) = @_;
Subroutine init: called CC=5 SCAR=16.5
Pod undocumented
38 21 ▶ defined $self->SUPER::init($args) or return;
Branch: 1 branch
BranchTrueFalseTotal
defined $self->SUPER::init($args) or return 21 0 21
39  
40 21 ▶ $self->{exceptions} = delete $args->{exceptions} || [];
Condition50%1/2
delete $args->{'exceptions'} || []
l!l
021
MC/DC0%0/1
delete $args->{'exceptions'} || []
delete $args->{'exceptions'}
Truth table50%1/2
A
A= delete $args->{'exceptions'}
Aresult
11
00
41 21 $self->{died} = delete $args->{died};
42 21 ▶ $self->hide($args->{hide} // 'NONE');
Condition50%1/2
$args->{"hide"} // "NONE"
l!l
021
MC/DC0%0/1
$args->{"hide"} // "NONE"
$args->{"hide"}
Truth table50%1/2
A
A= $args->{"hide"}
Aresult
11
00
43 21 ▶ $self->{on_die} = $args->{on_die} // 'ERROR';
Condition100%2/2
$args->{"on_die"} // "ERROR"
l!l
120
MC/DC100%1/1
$args->{"on_die"} // "ERROR"
$args->{"on_die"}
Truth table100%2/2
A
A= $args->{"on_die"}
Aresult
11
00
44 21 $self;
45 }
46  
47 #--------------------
48  
49 sub died(;$)
50 18 ▶{ my $self = shift;
Subroutine died: called CC=2 SCAR=6.9
Pod documented
51 18 ▶ @_ ? ($self->{died} = shift) : $self->{died};
Branch: 1 branch
BranchTrueFalseTotal
@_ ? : 15 3 18
52 }
53  
54  
55 6 ▶sub exceptions() { @{ $_[0]->{exceptions}} }
Subroutine exceptions: called CC=1 SCAR=0.0
Pod documented
56  
57  
58 3 ▶sub hides($) { $_[0]->{LRDT_hides}{$_[1]} }
Subroutine hides: called CC=1 SCAR=0.0
Pod documented
59  
60  
61 sub hide(@)
62 21 ▶{ my $self = shift;
Subroutine hide: called CC=2 SCAR=7.1
Pod documented
63 21 ▶ my @reasons = expand_reasons(@_ > 1 ? \@_ : shift);
Branch: 1 branch
BranchTrueFalseTotal
@_ > 1 ? : 0 21 21
64 21 $self->{LRDT_hides} = +{ map +($_ => 1), @reasons };
65 }
66  
67  
68 6 ▶sub die2reason() { $_[0]->{on_die} }
Subroutine die2reason: called CC=1 SCAR=0.0
Pod documented
69  
70 #--------------------
71  
72 sub log($$$$)
73 18 ▶{ my ($self, $opts, $reason, $message, $domain) = @_;
Subroutine log: called CC=8 SCAR=21.7
Pod documented
74  
75 18 ▶ unless($opts->{stack})
Branch: 1 branch
BranchTrueFalseTotal
unless ($opts->{"stack"}) 10 8 18
76 10 { my $mode = $self->mode;
77 $opts->{stack} = $self->collectStack
78 if $reason eq 'PANIC'
79 || ($mode==2 && $reason_code{$reason} >= $reason_code{ALERT})
80 10 ▶ || ($mode==3 && $reason_code{$reason} >= $reason_code{ERROR});
Branch: 1 branch
BranchTrueFalseTotal
if $reason eq "PANIC" or $mode == 2 and $Log::Report::Dispatcher::Try::reason_code{$reason} >= $Log::Report::Dispatcher::Try::reason_code{"ALERT"} or $mode == 3 and $Log::Report::Dispatcher::Try::reason_code{$reason} >= $Log::Report::Dispatcher::Try::reason_code{"ERROR"} 1 9 10
Condition50%6/12
$reason eq "PANIC" or $mode == 2 and $Log::Report::Dispatcher::Try::reason_code{$reason} >= $Log::Report::Dispatcher::Try::reason_code{"ALERT"} or $mode == 3 and $Log::Report::Dispatcher::Try::reason_code{$reason} >= $Log::Report::Dispatcher::Try::reason_code{"ERROR"}
l!l&&r!l&&!r
019
$reason eq "PANIC" or $mode == 2 and $Log::Report::Dispatcher::Try::reason_code{$reason} >= $Log::Report::Dispatcher::Try::reason_code{"ALERT"}
l!l&&r!l&&!r
0010
$mode == 2 and $Log::Report::Dispatcher::Try::reason_code{$reason} >= $Log::Report::Dispatcher::Try::reason_code{"ALERT"}
!ll&&!rl&&r
1000
$mode == 3 and $Log::Report::Dispatcher::Try::reason_code{$reason} >= $Log::Report::Dispatcher::Try::reason_code{"ERROR"}
!ll&&!rl&&r
901
MC/DC20%1/5
$reason eq "PANIC" or $mode == 2 and $Log::Report::Dispatcher::Try::reason_code{$reason} >= $Log::Report::Dispatcher::Try::reason_code{"ALERT"} or $mode == 3 and $Log::Report::Dispatcher::Try::reason_code{$reason} >= $Log::Report::Dispatcher::Try::reason_code{"ERROR"}
$reason eq "PANIC" $mode == 2 $Log::Report::Dispatcher::Try::reason_code{$reason} >= $Log::Report::Dispatcher::Try::reason_code{"ALERT"} $mode == 3 $Log::Report::Dispatcher::Try::reason_code{$reason} >= $Log::Report::Dispatcher::Try::reason_code{"ERROR"}
Truth table25%2/8
A or B and C or D and E
A= $reason eq "PANIC"B= $mode == 2C= $Log::Report::Dispatcher::Try::reason_code{$reason} >= $Log::Report::Dispatcher::Try::reason_code{"ALERT"}D= $mode == 3E= $Log::Report::Dispatcher::Try::reason_code{$reason} >= $Log::Report::Dispatcher::Try::reason_code{"ERROR"}
ABCDEresult
1XXXX1
011XX1
00X111
010111
00X0X0
00X100
0100X0
010100
81 }
82  
83 18 ▶ $opts->{location} ||= '';
Condition100%2/2
$opts->{"location"} ||= ""
l!l
171
MC/DC100%1/1
$opts->{"location"} ||= ""
$opts->{"location"}
Truth table100%2/2
A
A= $opts->{"location"}
Aresult
11
00
84  
85 18 push @{$self->{exceptions}},
86 Log::Report::Exception->new(reason => $reason, report_opts => $opts, message => $message);
87  
88 18 $self;
89 }
90  
91  
92 0 ▶sub reportFatal(@) { my $s = shift; $_->throw(@_) for $s->wasFatal }
Subroutine reportFatal: not called CC=2 SCAR=17.9
Pod documented
93 2 ▶sub reportAll(@) { my $s = shift; $_->throw(@_) for $s->exceptions }
Subroutine reportAll: called CC=2 SCAR=6.9
Pod documented
94  
95 #--------------------
96  
97 4 ▶sub failed() { defined shift->{died} }
Subroutine failed: called CC=1 SCAR=0.0
Pod documented
98 0 ▶sub success() { ! defined shift->{died} }
Subroutine success: not called CC=1 SCAR=6.9
Pod documented
99  
100  
101 sub wasFatal(@)
102 24 ▶{ my ($self, %args) = @_;
Subroutine wasFatal: called CC=6 SCAR=18.5
Pod documented
103 24 ▶ defined $self->{died} or return ();
Branch: 1 branch
BranchTrueFalseTotal
defined $self->{"died"} or return () 17 7 24
104  
105 17 ▶ my $ex = first { $_->isFatal } @{$self->{exceptions}}
Subroutine __ANON__: called CC=1 SCAR=0.1
Branch: 1 branch
BranchTrueFalseTotal
my $ex = &first(sub { $_->isFatal; } , @{$$self{"exceptions"};}) or return () 17 0 17
106 or return ();
107  
108 17 ▶ my $tag = $args{tag} // $args{class};
Condition66%2/3
$args{"tag"} // $args{"class"}
l!l&&r!l&&!r
1016
MC/DC50%1/2
$args{"tag"} // $args{"class"}
$args{"tag"} $args{"class"}
Truth table66%2/3
A // B
A= $args{"tag"}B= $args{"class"}
ABresult
1X1
011
000
109  
110 # There can only be one fatal exception. Is it in the class?
111 17 ▶ (! $tag || $ex->taggedWith($tag)) ? $ex : ();
Branch: 1 branch
BranchTrueFalseTotal
!$tag || $ex->taggedWith($tag) ? : 17 0 17
Condition66%2/3
not $tag or $ex->taggedWith($tag)
l!l&&r!l&&!r
1610
MC/DC0%0/2
not $tag or $ex->taggedWith($tag)
not $tag $ex->taggedWith($tag)
Truth table66%2/3
not(A) or B
A= not $tagB= $ex->taggedWith($tag)
ABresult
1X1
011
000
112 }
113  
114  
115 sub showStatus()
116 3 ▶{ my $self = shift;
Subroutine showStatus: called CC=2 SCAR=7.1
Pod documented
117 3 ▶ my $fatal = $self->wasFatal or return '';
Branch: 1 branch
BranchTrueFalseTotal
my $fatal = $self->wasFatal or return "" 3 0 3
118 3 __x"try-block stopped with {reason}: {text}", reason => $fatal->reason, text => $self->died;
119 }
120  
121 17 1;
« Log/Report/Dispatcher/Log4perl.pm ↑ Summary Log/Report/Exception.pm »