lib/Neo4j/Error.pm

filter: Statementstmt 100% 76 / 76 Branchbran 97.6% 41 / 42 Conditioncond 100% 36 / 36 MC/DCmcdc 100% 22 / 22 Subroutinesub 100% 19 / 19 Podpod 100% 12 / 12 totaltotal 99.5% 206 / 207 CC 36 SCAR 21.7
CC
36
Cov
99%
new
15.0
append_new
12.0
as_string
9.0
CRAP 8.7
« blib/lib/Neo4j/Error.pm ↑ Summary blib/lib/Neo4j/Error/Server.pm »
1 5 ▶use v5.10;
Subroutine BEGIN: called CC=1 SCAR=0.0
2 5 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 5 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 package Neo4j::Error;
6 # ABSTRACT: Common Neo4j exception representations
7 5 $Neo4j::Error::VERSION = '0.01';
8  
9 5 ▶use List::Util 1.33 qw(first none);
Subroutine BEGIN: called CC=1 SCAR=0.0
10 5 ▶use Module::Load qw(load);
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 5 my @SOURCES = qw( Server Network Internal Usage );
13 5 my @KEYS = qw(
14 as_string
15 category
16 classification
17 code
18 is_retryable
19 message
20 raw
21 related
22 source
23 title
24 trace
25 );
26  
27  
28 sub _croak {
29 18 ▶ require Carp;
Subroutine _croak: called CC=1 SCAR=0.0
30 18 Carp::croak(@_);
31 }
32  
33  
34 sub new {
35 53 ▶ my ($class, $source, $info, @extra) = @_;
Subroutine new: called CC=15 SCAR=27.1
Pod documented
36
37 53 ▶ _croak "Call as instance method unsupported for %s->new()", __PACKAGE__ if ref $class ne '';
Branch: 1 branch
BranchTrueFalseTotal
if ref $class ne "" 1 52 53
38 52 ▶ _croak sprintf "Source param required for %s->new()", __PACKAGE__ unless $source && ref $source eq '';
Branch: 1 branch
BranchTrueFalseTotal
unless $source and ref $source eq "" 2 50 52
Condition100%3/3
$source and ref $source eq ""
!ll&&!rl&&r
1150
MC/DC100%2/2
$source and ref $source eq ""
$source ref $source eq ""
Truth table100%3/3
A and B
A= $sourceB= ref $source eq ""
ABresult
0X0
100
111
39 50 ▶ if ($class eq __PACKAGE__) {
Branch: 1 branch
BranchTrueFalseTotal
if ($class eq __PACKAGE__) { } 42 8 50
40 42 ▶ $class = first { $_ eq $source } @SOURCES;
Subroutine __ANON__: called CC=1 SCAR=0.0
41 42 ▶ _croak sprintf "Source '%s' is unsupported for %s->new()", $source, __PACKAGE__ unless $class;
Branch: 1 branch
BranchTrueFalseTotal
unless $class 4 38 42
42 38 $class = __PACKAGE__ . "::$class";
43 38 load $class;
44 }
45 else { # subclass
46 8 ▶ _croak sprintf "Class %s fails to implement source()", $class unless $class->can('source');
Branch: 1 branch
BranchTrueFalseTotal
unless $class->can("source") 1 7 8
47 7 ▶ _croak sprintf "Ambiguous source %s for %s", $source, $class if $class->source ne $source;
Branch: 1 branch
BranchTrueFalseTotal
if $class->source ne $source 1 6 7
48 }
49
50 44 ▶ if ($info && ref $info eq '') {
Branch: 2 branches
BranchTrueFalseTotal
if ($info and ref $info eq '') { } 6 38 44
elsif (ref $info ne 'HASH') { } 2 36 38
Condition100%3/3
$info and ref $info eq ""
!ll&&!rl&&r
1376
MC/DC100%2/2
$info and ref $info eq ""
$info ref $info eq ""
Truth table100%3/3
A and B
A= $infoB= ref $info eq ""
ABresult
0X0
100
111
51 6 $info = { as_string => '' . $info };
52 }
53 elsif (ref $info ne 'HASH') {
54 2 _croak sprintf "Hashref or string required for %s->new()", $class;
55 }
56 42 ▶ _croak "Too many arguments for $class->new()" if @extra;
Branch: 1 branch
BranchTrueFalseTotal
if @extra 2 40 42
57
58 40 my $self = bless {}, $class;
59 40 $self->{$_} = $info->{$_} for @KEYS;
60
61 40 require Devel::StackTrace;
62 40 ▶ my $trace_config = $info->{trace} // {};
Condition100%2/2
$info->{"trace"} // {}
l!l
634
MC/DC100%1/1
$info->{"trace"} // {}
$info->{"trace"}
Truth table100%2/2
A
A= $info->{"trace"}
Aresult
11
00
63 40 $trace_config->{skip_frames}++;
64 40 ▶ $trace_config->{message} //= $self->as_string;
Condition100%3/3
$trace_config->{"message"} //= $self->as_string
l!l&&r!l&&!r
12910
MC/DC100%2/2
$trace_config->{"message"} //= $self->as_string
$trace_config->{"message"} $self->as_string
Truth table100%3/3
A //= B
A= $trace_config->{"message"}B= $self->as_string
ABresult
1X1
011
000
65 40 $self->{trace} = Devel::StackTrace->new(%$trace_config);
66
67 40 return $self;
68 }
69  
70  
71 sub append_new {
72 12 ▶ my ($self, $source, $related, @extra) = @_;
Subroutine append_new: called CC=12 SCAR=24.9
Pod documented
73
74 12 ▶ _croak sprintf "Source param required for %s->append_new()", __PACKAGE__ unless $source && ref $source eq '';
Branch: 1 branch
BranchTrueFalseTotal
unless $source and ref $source eq "" 2 10 12
Condition100%3/3
$source and ref $source eq ""
!ll&&!rl&&r
1110
MC/DC100%2/2
$source and ref $source eq ""
$source ref $source eq ""
Truth table100%3/3
A and B
A= $sourceB= ref $source eq ""
ABresult
0X0
100
111
75 10 ▶ _croak sprintf "Ambiguous source %s for %s", $source, $self if ref $self eq '' && $self->can('source') && $self->source ne $source;
Branch: 1 branch
BranchTrueFalseTotal
if ref $self eq "" and $self->can("source") and $self->source ne $source 1 9 10
Condition100%6/6
ref $self eq "" and $self->can("source") and $self->source ne $source
!ll&&!rl&&r
811
ref $self eq "" and $self->can("source")
!ll&&!rl&&r
172
MC/DC100%3/3
ref $self eq "" and $self->can("source") and $self->source ne $source
ref $self eq "" $self->can("source") $self->source ne $source
Truth table100%4/4
A and B and C
A= ref $self eq ""B= $self->can("source")C= $self->source ne $source
ABCresult
0XX0
10X0
1100
1111
76
77 9 ▶ if ($related && ref $related eq '') {
Branch: 2 branches
BranchTrueFalseTotal
if ($related and ref $related eq '') { } 1 8 9
elsif (ref $related ne 'HASH') { } 2 6 8
Condition100%3/3
$related and ref $related eq ""
!ll&&!rl&&r
171
MC/DC100%2/2
$related and ref $related eq ""
$related ref $related eq ""
Truth table100%3/3
A and B
A= $relatedB= ref $related eq ""
ABresult
0X0
100
111
78 1 $related = { as_string => '' . $related };
79 }
80 elsif (ref $related ne 'HASH') {
81 2 _croak sprintf "Hashref or string required for %s->append_new()", __PACKAGE__;
82 }
83
84 7 ▶ my $class = ref $self eq '' ? $self : __PACKAGE__;
Branch: 1 branch
BranchTrueFalseTotal
ref $self eq '' ? : 6 1 7
85 7 $related->{trace}{skip_frames}++;
86 7 $related = $class->new($source => $related, @extra);
87 4 ▶ return $related if ref $self eq ''; # if called as class method, behave just like new()
Branch: 1 branch
BranchTrueFalseTotal
if ref $self eq "" 3 1 4
88
89 1 my $tail = $self;
90 1 ▶ $tail = $tail->{related} while $tail->{related};
Branch: 1 branch
BranchTrueFalseTotal
$tail->{"related"} and do { $tail = $tail->{"related"} } 0 1 1
91 1 $tail->{related} = $related;
92 1 return $self;
93 }
94  
95  
96 sub as_string {
97 61 ▶ my ($self) = @_;
Subroutine as_string: called CC=9 SCAR=22.0
Pod documented
98
99 61 my $str = $self->{as_string};
100 61 ▶ return $str if defined $str;
Branch: 1 branch
BranchTrueFalseTotal
if defined $str 32 29 61
101
102 29 my $code = $self->code;
103 29 my $message = $self->message;
104 29 ▶ $str = sprintf "%s: %s", $code, $message if $code && $message;
Branch: 1 branch
BranchTrueFalseTotal
if $code and $message 7 22 29
Condition100%3/3
$code and $message
!ll&&!rl&&r
1667
MC/DC100%2/2
$code and $message
$code $message
Truth table100%3/3
A and B
A= $codeB= $message
ABresult
0X0
100
111
105 29 ▶ $str = sprintf "%s %s", ref $self, $code if $code && ! $message;
Branch: 1 branch
BranchTrueFalseTotal
if $code and not $message 6 23 29
Condition100%3/3
$code and not $message
!ll&&!rl&&r
1676
MC/DC100%2/2
$code and not $message
$code not $message
Truth table100%3/3
A and not(B)
A= $codeB= not $message
ABresult
0X0
100
111
106 29 ▶ $str = sprintf "%s", $message if ! $code && $message;
Branch: 1 branch
BranchTrueFalseTotal
if not $code and $message 1 28 29
Condition100%3/3
not $code and $message
!ll&&!rl&&r
13151
MC/DC100%2/2
not $code and $message
not $code $message
Truth table100%3/3
not(A) and B
A= not $codeB= $message
ABresult
0X0
100
111
107 29 ▶ $str = $self->trace unless $str; # last resort
Branch: 1 branch
BranchTrueFalseTotal
unless $str 15 14 29
108 29 return $self->{as_string} = $str;
109 }
110  
111  
112 18 ▶sub message { shift->{message} // '' }
Subroutine message: called CC=2 SCAR=6.9
Pod documented
Condition100%2/2
+(shift())->{"message"} // ""
l!l
711
MC/DC100%1/1
+(shift())->{"message"} // ""
+(shift())->{"message"}
Truth table100%2/2
A
A= +(shift())->{"message"}
Aresult
11
00
113 18 ▶sub code { shift->{code} // '' }
Subroutine code: called CC=2 SCAR=6.9
Pod documented
Condition100%2/2
+(shift())->{"code"} // ""
l!l
513
MC/DC100%1/1
+(shift())->{"code"} // ""
+(shift())->{"code"}
Truth table100%2/2
A
A= +(shift())->{"code"}
Aresult
11
00
114 3 ▶sub classification { '' }
Subroutine classification: called CC=1 SCAR=0.0
Pod documented
115 3 ▶sub category { '' }
Subroutine category: called CC=1 SCAR=0.0
Pod documented
116 3 ▶sub title { '' }
Subroutine title: called CC=1 SCAR=0.0
Pod documented
117 2 ▶sub is_retryable { !!0 }
Subroutine is_retryable: called CC=1 SCAR=0.0
Pod documented
118  
119 6 ▶sub related { shift->{related} }
Subroutine related: called CC=1 SCAR=0.0
Pod documented
120  
121 2 ▶sub raw { shift->{raw} }
Subroutine raw: called CC=1 SCAR=0.0
Pod documented
122 21 ▶sub trace { shift->{trace} }
Subroutine trace: called CC=1 SCAR=0.0
Pod documented
123  
124  
125 5 1;
126  
127 __END__
« blib/lib/Neo4j/Error.pm ↑ Summary blib/lib/Neo4j/Error/Server.pm »