HTTP/Print.pm

filter: Statementstmt 77.7% 35 / 45 Branchbran 40.0% 4 / 10 Conditioncond 33.3% 1 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 100% 8 / 8 Podpod 100% 1 / 1 totaltotal 71.0% 49 / 69 SCAR 21.4
CC
7
Cov
69%
err
11.3
__ANON__
2.0
BEGIN
1.0
CRAP 8.5
↑ Summary HTTP/AllError.pm »
1 package Error::Pure::HTTP::Print;
2  
3 # Pragmas.
4 3 ▶use base qw(Exporter);
Subroutine BEGIN: called CC=1 SCAR=0.0
5 3 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 3 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 # Modules.
9 3 ▶use Error::Pure::Utils qw(err_helper);
Subroutine BEGIN: called CC=1 SCAR=0.0
10 3 ▶use List::MoreUtils qw(none);
Subroutine BEGIN: called CC=1 SCAR=0.0
11 3 ▶use Readonly;
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13 # Constants.
14 3 Readonly::Array our @EXPORT_OK => qw(err);
15 3 Readonly::Scalar my $EMPTY_STR => q{};
16 3 Readonly::Scalar my $EVAL => 'eval {...}';
17  
18 # Version.
19 3 our $VERSION = 0.14;
20  
21 # Ignore die signal.
22 3 $SIG{__DIE__} = 'IGNORE';
23  
24 # Process error.
25 sub err {
26 5 ▶ my @msg = @_;
Subroutine err: called CC=6 SCAR=24.3
Pod documented
27  
28 # Get errors structure.
29 5 my @errors = err_helper(@msg);
30  
31 # Error message.
32 5 my $e = $errors[-1]->{'msg'}->[0];
33 5 ▶ if (! defined $e) {
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $e) { } 0 5 5
34 0 $e = 'undef';
35 } else {
36 5 chomp $e;
37 }
38  
39 # Finalize in main on last err.
40 5 my $stack_ar = $errors[-1]->{'stack'};
41 5 ▶ if ($stack_ar->[-1]->{'class'} eq 'main'
Branch: 1 branch
BranchTrueFalseTotal
if ($stack_ar->[-1]{'class'} eq 'main' and &none(sub { $_ eq $EVAL or $_ =~ /^eval '/ms; } , map({$_->{'sub'};} @{$stack_ar;}))) { } 0 5 5
Condition33%1/3
$stack_ar->[-1]{"class"} eq "main" and &none(sub { $_ eq $EVAL or $_ =~ /^eval '/ms; } , map({$_->{"sub"};} @{$stack_ar;}))
!ll&&!rl&&r
050
MC/DC0%0/2
$stack_ar->[-1]{"class"} eq "main" and &none(sub { $_ eq $EVAL or $_ =~ /^eval '/ms; } , map({$_->{"sub"};} @{$stack_ar;}))
$stack_ar->[-1]{"class"} eq "main" &none(sub { $_ eq $EVAL or $_ =~ /^eval '/ms; } , map({$_->{"sub"};} @{$stack_ar;}))
Truth table33%1/3
A and B
A= $stack_ar->[-1]{"class"} eq "main"B= &none(sub { $_ eq $EVAL or $_ =~ /^eval '/ms; } , map({$_->{"sub"};} @{$stack_ar;}))
ABresult
0X0
100
111
42 10 ▶ && none { $_ eq $EVAL || $_ =~ /^eval '/ms }
Subroutine __ANON__: called CC=2 SCAR=6.9
Branch: 1 branch
BranchTrueFalseTotal
$_ eq $EVAL or $_ =~ /^eval '/ms 5 5 10
43 10 map { $_->{'sub'} } @{$stack_ar}) {
44  
45 0 my $class = $errors[-1]->{'stack'}->[0]->{'class'};
46 0 ▶ if ($class eq 'main') {
Branch: 1 branch
BranchTrueFalseTotal
if ($class eq "main") 0 0 0
47 0 $class = $EMPTY_STR
48 }
49 0 ▶ if ($class) {
Branch: 1 branch
BranchTrueFalseTotal
if ($class) 0 0 0
50 0 $class .= ': ';
51 }
52 0 print "Content-type: text/plain\n\n";
53 0 print $class."$e\n";
54 0 return;
55  
56 # Die for eval.
57 } else {
58 5 die "$e\n";
59 }
60  
61 0 return;
62 }
63  
64 3 1;
65  
66 __END__
↑ Summary HTTP/AllError.pm »