OO/Error.pm

filter: Statementstmt 43.1% 25 / 58 Branchbran 0.0% 0 / 16 Conditioncond 0.0% 0 / 15 MC/DCmcdc 0.0% 0 / 10 Subroutinesub 50.0% 6 / 12 Podpod 75.0% 3 / 4 totaltotal 29.5% 34 / 115 CC 14 SCAR 33.0
CC
14
Cov
28%
as_string
56.0
BUILD
42.0
__ANON__
6.0
CRAP 27.1
↑ Summary OO/Functions.pm »
1  
2 package Net::SSLeay::OO::Error;
3  
4 5 ▶use Net::SSLeay;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 5 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 has 'err' => isa => 'Int',
8 is => 'ro',
9 required => 1,
10 0 ▶ default => sub {
Subroutine __ANON__: not called CC=2 SCAR=17.9
11 0 ▶ Net::SSLeay::ERR_get_error
Branch: 1 branch
BranchTrueFalseTotal
&Net::SSLeay::ERR_get_error() or die "no OpenSSL error to get" 0 0 0
12 or die "no OpenSSL error to get";
13 5 };
14  
15 0 ▶sub ssl_error_pending {
Subroutine ssl_error_pending: not called CC=1 SCAR=6.9
Pod documented
16 0 Net::SSLeay::ERR_peek_error;
17 }
18  
19 5 has 'error_code' => isa => "Int",
20 is => "ro",
21 ;
22  
23 5 has 'library_name' => isa => "Str",
24 is => "ro",
25 ;
26  
27 5 has 'function_name' => isa => "Str",
28 is => "ro",
29 ;
30  
31 5 has 'reason_string' => isa => "Str",
32 is => "ro",
33 ;
34  
35 5 has 'next' => isa => __PACKAGE__,
36 is => "ro",
37 ;
38  
39 0 ▶sub BUILD {
Subroutine BUILD: not called CC=6 SCAR=37.4
Pod undocumented
40 0 my $self = shift;
41 0 my $ssl_error = $self->error_string;
42 0 ( undef, my @fields ) = split ":", $ssl_error, 5;
43 0 ▶ $self->{error_code} ||= hex( shift @fields );
Condition0%0/3
$self->{"error_code"} ||= hex shift @fields
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->{"error_code"} ||= hex shift @fields
$self->{"error_code"} hex shift @fields
Truth table0%0/3
A ||= B
A= $self->{"error_code"}B= hex shift @fields
ABresult
1X1
011
000
44 0 ▶ $self->{library_name} ||= shift @fields;
Condition0%0/3
$self->{"library_name"} ||= shift @fields
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->{"library_name"} ||= shift @fields
$self->{"library_name"} shift @fields
Truth table0%0/3
A ||= B
A= $self->{"library_name"}B= shift @fields
ABresult
1X1
011
000
45 0 ▶ $self->{function_name} ||= shift @fields;
Condition0%0/3
$self->{"function_name"} ||= shift @fields
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->{"function_name"} ||= shift @fields
$self->{"function_name"} shift @fields
Truth table0%0/3
A ||= B
A= $self->{"function_name"}B= shift @fields
ABresult
1X1
011
000
46 0 ▶ $self->{reason_string} ||= shift @fields;
Condition0%0/3
$self->{"reason_string"} ||= shift @fields
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->{"reason_string"} ||= shift @fields
$self->{"reason_string"} shift @fields
Truth table0%0/3
A ||= B
A= $self->{"reason_string"}B= shift @fields
ABresult
1X1
011
000
47  
48 # OpenSSL throws an entire stack backtrace, so capture all the
49 # outstanding SSL errors and chain them off this one.
50 0 ▶ if (ssl_error_pending) {
Branch: 1 branch
BranchTrueFalseTotal
if (ssl_error_pending()) 0 0 0
51 0 $self->{next} = ( ref $self )->new();
52 }
53 }
54  
55 5 has 'message' => isa => "Str",
56 is => "rw",
57 ;
58  
59 0 ▶sub die_if_ssl_error {
Subroutine die_if_ssl_error: not called CC=2 SCAR=17.9
Pod documented
60 0 my $message = shift;
61 0 ▶ if (ssl_error_pending) {
Branch: 1 branch
BranchTrueFalseTotal
if (ssl_error_pending()) 0 0 0
62 0 die __PACKAGE__->new( message => $message );
63 }
64 }
65  
66 0 ▶sub as_string {
Subroutine as_string: not called CC=7 SCAR=40.3
Pod documented
67 0 my $self = shift;
68 0 my $message = $self->message;
69 0 ▶ if ($message) {
Branch: 1 branch
BranchTrueFalseTotal
if ($message) { } 0 0 0
70 0 ▶ unless ( $message =~ / / ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($message =~ / /) 0 0 0
71 0 $message = "During `$message'";
72 }
73 0 $message .= ": ";
74 }
75 else {
76 0 $message = "";
77 }
78 0 my $reason_string = $self->reason_string;
79 0 my $result = do {
80 0 ▶ if ( $reason_string eq "system lib" ) { # FIXME: lang
Branch: 1 branch
BranchTrueFalseTotal
if ($reason_string eq 'system lib') { } 0 0 0
81 0 sprintf( "%s%.8x: trace: %s (%s)",
82 $message, $self->error_code,
83 $self->function_name, $self->library_name );
84 }
85 else {
86 0 sprintf("%sOpenSSL error %.8x: %s during %s (%s)",
87 $message, $self->error_code,
88 $self->reason_string, $self->function_name,
89 $self->library_name
90 );
91 }
92 };
93 0 ▶ if ( $self->next ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->next) 0 0 0
94 0 $result .= "\n" . " then " . $self->next->as_string;
95 }
96 0 ▶ if ( $result =~ m{\n} and $result !~ m{\n\Z} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($result =~ /\n/ and not $result =~ /\n\Z/) 0 0 0
Condition0%0/3
$result =~ /\n/ and not $result =~ /\n\Z/
!ll&&!rl&&r
000
MC/DC0%0/2
$result =~ /\n/ and not $result =~ /\n\Z/
$result =~ /\n/ not $result =~ /\n\Z/
Truth table0%0/3
A and not(B)
A= $result =~ /\n/B= not $result =~ /\n\Z/
ABresult
0X0
100
111
97 0 $result .= "\n";
98 }
99 0 $result;
100 }
101  
102 use overload
103 5 ▶ '""' => \&as_string,
Subroutine BEGIN: called CC=1 SCAR=0.0
104 5 ;
105  
106 5 ▶use Sub::Exporter -setup =>
Subroutine BEGIN: called CC=1 SCAR=0.0
107 5 { exports => [qw(die_if_ssl_error ssl_error_pending)], };
108  
109 5 ▶use Net::SSLeay::OO::Functions sub {
Subroutine BEGIN: called CC=1 SCAR=0.2
Subroutine __ANON__: called CC=1 SCAR=0.2
110 40 my $code = shift;
111 0 ▶ sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
112 0 my $self = shift;
113 0 $code->( $self->err, @_ );
114 }
115 5 };
116  
117 5 1;
118  
119 __END__
↑ Summary OO/Functions.pm »