Log/Report/Exception.pm

filter: Statementstmt 89.4% 51 / 57 Branchbran 57.1% 8 / 14 Conditioncond 27.2% 3 / 11 MC/DCmcdc 0.0% 0 / 7 Subroutinesub 89.4% 17 / 19 Podpod 90.9% 10 / 11 totaltotal 74.7% 89 / 119 CC 12 SCAR 12.1
CC
12
Cov
76%
message
10.8
print
6.0
throw
4.0
CRAP 3.3
« Log/Report/Dispatcher/Try.pm ↑ Summary Log/Report/Dispatcher/LogDispatch.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::Exception;{
13 17 our $VERSION = '1.46';
14 }
15  
16  
17 17 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
18 17 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
19  
20 17 ▶use Log::Report 'log-report', import => [ qw/__x error report/ ];
Subroutine BEGIN: called CC=1 SCAR=0.0
21 17 ▶use Log::Report::Util qw/is_fatal to_html/;
Subroutine BEGIN: called CC=1 SCAR=0.0
22  
23 17 ▶use POSIX qw/locale_h/;
Subroutine BEGIN: called CC=1 SCAR=0.0
24 17 ▶use Scalar::Util qw/blessed/;
Subroutine BEGIN: called CC=1 SCAR=0.0
25  
26 #--------------------
27  
28 use overload
29 17 ▶ '""' => 'toString',
Subroutine BEGIN: called CC=1 SCAR=0.0
30 22 ▶ bool => sub {1}, # avoid accidental serialization of message
Subroutine __ANON__: called CC=1 SCAR=0.0
31 17 fallback => 1;
32  
33 #--------------------
34  
35 sub new($@)
36 25 ▶{ my ($class, %args) = @_;
Subroutine new: called CC=2 SCAR=7.1
Pod documented
37 25 ▶ $args{report_opts} ||= {};
Condition50%1/2
$args{"report_opts"} ||= {}
l!l
250
MC/DC0%0/1
$args{"report_opts"} ||= {}
$args{"report_opts"}
Truth table50%1/2
A
A= $args{"report_opts"}
Aresult
11
00
38 25 bless \%args, $class;
39 }
40  
41 #--------------------
42  
43 25 ▶sub report_opts() { $_[0]->{report_opts} }
Subroutine report_opts: called CC=1 SCAR=0.0
Pod documented
44  
45  
46 sub reason(;$)
47 9 ▶{ my $self = shift;
Subroutine reason: called CC=2 SCAR=7.2
Pod documented
48 9 ▶ @_ ? $self->{reason} = uc(shift) : $self->{reason};
Branch: 1 branch
BranchTrueFalseTotal
@_ ? : 0 9 9
49 }
50  
51  
52 sub isFatal()
53 25 ▶{ my $self = shift;
Subroutine isFatal: called CC=2 SCAR=6.9
Pod documented
54 25 my $opts = $self->report_opts;
55 25 ▶ exists $opts->{is_fatal} ? $opts->{is_fatal} : is_fatal $self->{reason};
Branch: 1 branch
BranchTrueFalseTotal
exists $opts->{'is_fatal'} ? : 2 23 25
56 }
57  
58  
59 sub message(;$)
60 20 ▶{ my $self = shift;
Subroutine message: called CC=4 SCAR=23.7
Pod documented
61 20 ▶ @_ or return $self->{message};
Branch: 1 branch
BranchTrueFalseTotal
@_ or return $self->{"message"} 0 20 20
62  
63 0 my $msg = shift;
64 0 ▶ blessed $msg && $msg->isa('Log::Report::Message')
Branch: 1 branch
BranchTrueFalseTotal
builtin::blessed($msg) and $msg->isa("Log::Report::Message") or &error(&__x("message() of exception expects Log::Report::Message, got {what UNKNOWN}.", "what", $msg)) 0 0 0
Condition0%0/3
builtin::blessed($msg) and $msg->isa("Log::Report::Message")
!ll&&!rl&&r
000
MC/DC0%0/2
builtin::blessed($msg) and $msg->isa("Log::Report::Message")
builtin::blessed($msg) $msg->isa("Log::Report::Message")
Truth table0%0/3
A and B
A= builtin::blessed($msg)B= $msg->isa("Log::Report::Message")
ABresult
0X0
100
111
65 or error __x"message() of exception expects Log::Report::Message, got {what UNKNOWN}.", what => $msg;
66  
67 0 $self->{message} = $msg;
68 }
69  
70 #--------------------
71  
72 2 ▶sub taggedWith($) { $_[0]->message->taggedWith($_[1]) }
Subroutine taggedWith: called CC=1 SCAR=0.0
Pod documented
73  
74  
75 17 *inClass = \&taggedWith;
76  
77  
78 sub throw(@)
79 3 ▶{ my $self = shift;
Subroutine throw: called CC=4 SCAR=13.9
Pod documented
80 3 my %opts = ( %{$self->{report_opts}}, @_ );
81  
82 3 my $reason;
83 3 ▶ if($reason = delete $opts{reason})
Branch: 1 branch
BranchTrueFalseTotal
if ($reason = delete $opts{'reason'}) { } 1 2 3
84 1 ▶ { exists $opts{is_fatal} or $opts{is_fatal} = is_fatal $reason;
Branch: 1 branch
BranchTrueFalseTotal
exists $opts{"is_fatal"} or $opts{"is_fatal"} = &is_fatal($reason) 0 1 1
85 }
86 else
87 2 { $reason = $self->{reason};
88 }
89  
90 3 ▶ $opts{stack} ||= Log::Report::Dispatcher->collectStack;
Condition66%2/3
$opts{"stack"} ||= "Log::Report::Dispatcher"->collectStack
l!l&&r!l&&!r
210
MC/DC0%0/2
$opts{"stack"} ||= "Log::Report::Dispatcher"->collectStack
$opts{"stack"} "Log::Report::Dispatcher"->collectStack
Truth table66%2/3
A ||= B
A= $opts{"stack"}B= "Log::Report::Dispatcher"->collectStack
ABresult
1X1
011
000
91 3 report \%opts, $reason, $self;
92 }
93  
94 # where the throw is handled is not interesting
95 9 ▶sub PROPAGATE($$) { $_[0] }
Subroutine PROPAGATE: called CC=1 SCAR=0.0
Pod undocumented
96  
97  
98 sub toString(;$)
99 5 ▶{ my ($self, $locale) = @_;
Subroutine toString: called CC=2 SCAR=7.1
Pod documented
100 5 my $msg = $self->message;
101 5 ▶ lc($self->{reason}).': '.(ref $msg ? $msg->toString($locale) : $msg)."\n";
Branch: 1 branch
BranchTrueFalseTotal
ref $msg ? : 5 0 5
102 }
103  
104  
105 0 ▶sub toHTML(;$) { to_html($_[0]->toString($_[1])) }
Subroutine toHTML: not called CC=1 SCAR=6.9
Pod documented
106  
107  
108 sub print(;$)
109 0 ▶{ my $self = shift;
Subroutine print: not called CC=2 SCAR=17.9
Pod documented
110 0 ▶ (shift || *STDERR)->print($self->toString);
Condition0%0/3
shift() || *STDERR
l!l&&r!l&&!r
000
MC/DC0%0/2
shift() || *STDERR
shift() *STDERR
Truth table0%0/3
A || B
A= shift()B= *STDERR
ABresult
1X1
011
000
111 }
112  
113 17 1;
« Log/Report/Dispatcher/Try.pm ↑ Summary Log/Report/Dispatcher/LogDispatch.pm »