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/WebMVC0/Partial/Session2.pm ↑ Summary blib/lib/YATT/Lite/VarTypes.pm »
1 package YATT::Lite::Error; sub Error () {__PACKAGE__}
2 53 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 53 ▶use warnings qw(FATAL all NONFATAL misc);
Subroutine BEGIN: called CC=1 SCAR=0.0
4 53 ▶use parent qw(YATT::Lite::Object);
Subroutine BEGIN: called CC=1 SCAR=0.0
5 53 ▶use constant DEBUG_VERBOSE => $ENV{YATT_DEBUG_VERBOSE};
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 53 ▶use Exporter qw/import/;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 53 our @EXPORT_OK = qw/Error/;
9 53 our @EXPORT = @EXPORT_OK;
10  
11 53 ▶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 53 reason format args/;
15 53 ▶use overload qw("" message
Subroutine BEGIN: called CC=1 SCAR=0.0
16 eq streq
17 bool has_error
18 53 );
19 53 ▶use YATT::Lite::Util qw(lexpand untaint_any);
Subroutine BEGIN: called CC=1 SCAR=0.0
20 53 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
21 53 require Scalar::Util;
22  
23 3 ▶sub has_error {
Subroutine has_error: called CC=1 SCAR=0.0
Pod undocumented
24 3 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 71 ▶sub message {
Subroutine message: called CC=1 SCAR=0.0
Pod undocumented
34 71 my Error $error = shift;
35 71 my $msg = $error->reason . $error->place;
36 71 $msg .= $error->{backtrace} // '' if DEBUG_VERBOSE;
37 71 $msg;
38 }
39  
40 21 ▶sub byte_message {
Subroutine byte_message: called CC=1 SCAR=0.0
Pod undocumented
41 21 (my Error $error) = @_;
42 21 my $msg = $error->reason; # Place may not be useful for SiteApp->error_handler
43 21 Encode::_utf8_off($msg);
44 21 $msg;
45 }
46  
47 136 ▶sub reason {
Subroutine reason: called CC=6 SCAR=20.7
Pod undocumented
48 136 my Error $error = shift;
49 136 ▶ if ($error->{reason}) {
Branch: 2 branches
BranchTrueFalseTotal
if ($error->{'reason'}) { } 45 91 136
elsif ($error->{'format'}) { } 82 9 91
50 45 $error->{reason};
51 } elsif ($error->{format}) {
52 82 ▶ if (Scalar::Util::tainted($error->{format})) {
Branch: 1 branch
BranchTrueFalseTotal
if (&Scalar::Util::tainted($error->{"format"})) 0 82 82
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 53 ▶ BEGIN {
Subroutine BEGIN: called CC=2 SCAR=7.6
63 53 ▶ warnings->unimport(qw/redundant/) if $] >= 5.021002; # for sprintf
Branch: 1 branch
BranchTrueFalseTotal
if $] >= "5.021002" 53 0 53
64 }
65 sprintf $error->{format}, map {
66 157 ▶ defined $_ ? $_ : '(undef)'
Branch: 1 branch
BranchTrueFalseTotal
defined $_ ? : 157 0 157
67 82 } lexpand($error->{args});
68 } else {
69 9 "Unknown reason!"
70 }
71 }
72  
73 71 ▶sub place {
Subroutine place: called CC=5 SCAR=16.1
Pod undocumented
74 71 (my Error $err) = @_;
75 71 my $place = '';
76 71 ▶ $place .= " at file $err->{tmpl_file}" if $err->{tmpl_file};
Branch: 1 branch
BranchTrueFalseTotal
if $err->{"tmpl_file"} 47 24 71
77 71 ▶ $place .= " line $err->{tmpl_line}" if $err->{tmpl_line};
Branch: 1 branch
BranchTrueFalseTotal
if $err->{"tmpl_line"} 56 15 71
78 71 ▶ if ($err->{file}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($err->{"file"}) 69 2 71
79 69 $place .= ",\n reported from YATT Engine: $err->{file} line $err->{line}";
80 }
81 71 ▶ $place .= "\n" if $place ne ""; # To make 'warn/die' happy.
Branch: 1 branch
BranchTrueFalseTotal
if $place ne "" 70 1 71
82 71 $place;
83 }
84  
85 53 1;
« blib/lib/YATT/Lite/WebMVC0/Partial/Session2.pm ↑ Summary blib/lib/YATT/Lite/VarTypes.pm »