blib/lib/YATT/Lite/Error.pm

filter: Statementstmt 93.6% 59 / 63 Branchbran 72.7% 16 / 22 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 16 / 16 Podpod 0.0% 0 / 6 totaltotal 85.0% 91 / 107 CC 12 SCAR 12.3
CC
12
Cov
88%
reason
7.9
place
5.0
BEGIN
2.1
CRAP 3.4
« blib/lib/YATT/Lite/XHF/Dumper.pm ↑ Summary blib/lib/YATT/Lite/Macro.pm »
1 package YATT::Lite::Error; sub Error () {__PACKAGE__}
2 81 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 81 ▶use warnings qw(FATAL all NONFATAL misc);
Subroutine BEGIN: called CC=1 SCAR=0.0
4 81 ▶use parent qw(YATT::Lite::Object);
Subroutine BEGIN: called CC=1 SCAR=0.0
5 81 ▶use constant DEBUG_VERBOSE => $ENV{YATT_DEBUG_VERBOSE};
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 81 ▶use Exporter qw/import/;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 81 our @EXPORT_OK = qw/Error/;
9 81 our @EXPORT = @EXPORT_OK;
10  
11 81 ▶use YATT::Lite::MFields qw/file line tmpl_file tmpl_line
Subroutine BEGIN: called CC=1 SCAR=0.0
12 http_status_code
13 backtrace
14 81 reason format args/;
15 81 ▶use overload qw("" message
Subroutine BEGIN: called CC=1 SCAR=0.0
16 eq streq
17 bool has_error
18 81 );
19 81 ▶use YATT::Lite::Util qw(lexpand untaint_any);
Subroutine BEGIN: called CC=1 SCAR=0.0
20 81 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
21 81 require Scalar::Util;
22  
23 9 ▶sub has_error {
Subroutine has_error: called CC=1 SCAR=0.0
Pod undocumented
24 9 defined $_[0];
25 }
26  
27 1 ▶sub streq {
Subroutine streq: called CC=2 SCAR=7.1
Pod undocumented
28 1 my ($obj, $other, $inv) = @_;
29 1 ▶ ($obj, $other) = ($other, $obj) if $inv;
Branch: 1 branch
BranchTrueFalseTotal
if $inv 0 1 1
30 1 $obj->message eq $other;
31 }
32  
33 216 ▶sub message {
Subroutine message: called CC=1 SCAR=0.0
Pod undocumented
34 216 my Error $error = shift;
35 216 my $msg = $error->reason . $error->place;
36 216 $msg .= $error->{backtrace} // '' if DEBUG_VERBOSE;
37 216 $msg;
38 }
39  
40 92 ▶sub byte_message {
Subroutine byte_message: called CC=1 SCAR=0.0
Pod undocumented
41 92 (my Error $error) = @_;
42 92 my $msg = $error->reason; # Place may not be useful for SiteApp->error_handler
43 92 Encode::_utf8_off($msg);
44 92 $msg;
45 }
46  
47 534 ▶sub reason {
Subroutine reason: called CC=6 SCAR=20.7
Pod undocumented
48 534 my Error $error = shift;
49 534 ▶ if ($error->{reason}) {
Branch: 2 branches
BranchTrueFalseTotal
if ($error->{'reason'}) { } 92 442 534
elsif ($error->{'format'}) { } 433 9 442
50 92 $error->{reason};
51 } elsif ($error->{format}) {
52 433 ▶ if (Scalar::Util::tainted($error->{format})) {
Branch: 1 branch
BranchTrueFalseTotal
if (&Scalar::Util::tainted($error->{"format"})) 0 433 433
53 croak "Format is tainted in error reason("
54 .join(" ", map {
55 0 ▶ if (defined $_) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $_) { } 0 0 0
56 0 untaint_any($_)
57 } else {
58 0 '(undef)'
59 }
60 0 } $error->{format}, lexpand($error->{args})).")";
61 }
62 81 ▶ BEGIN {
Subroutine BEGIN: called CC=2 SCAR=7.6
63 81 ▶ warnings->unimport(qw/redundant/) if $] >= 5.021002; # for sprintf
Branch: 1 branch
BranchTrueFalseTotal
if $] >= "5.021002" 81 0 81
64 }
65 sprintf $error->{format}, map {
66 557 ▶ defined $_ ? $_ : '(undef)'
Branch: 1 branch
BranchTrueFalseTotal
defined $_ ? : 557 0 557
67 433 } lexpand($error->{args});
68 } else {
69 9 "Unknown reason!"
70 }
71 }
72  
73 216 ▶sub place {
Subroutine place: called CC=5 SCAR=16.1
Pod undocumented
74 216 (my Error $err) = @_;
75 216 my $place = '';
76 216 ▶ $place .= " at file $err->{tmpl_file}" if $err->{tmpl_file};
Branch: 1 branch
BranchTrueFalseTotal
if $err->{"tmpl_file"} 137 79 216
77 216 ▶ $place .= " line $err->{tmpl_line}" if $err->{tmpl_line};
Branch: 1 branch
BranchTrueFalseTotal
if $err->{"tmpl_line"} 146 70 216
78 216 ▶ if ($err->{file}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($err->{"file"}) 214 2 216
79 214 $place .= ",\n reported from YATT Engine: $err->{file} line $err->{line}";
80 }
81 216 ▶ $place .= "\n" if $place ne ""; # To make 'warn/die' happy.
Branch: 1 branch
BranchTrueFalseTotal
if $place ne "" 215 1 216
82 216 $place;
83 }
84  
85 81 1;
« blib/lib/YATT/Lite/XHF/Dumper.pm ↑ Summary blib/lib/YATT/Lite/Macro.pm »