blib/lib/Neo4j/Error/Server.pm untested

filter: Statementstmt 0.0% 0 / 43 Branchbran 0.0% 0 / 12 Conditioncond 0.0% 0 / 11 MC/DCmcdc n/a Subroutinesub 0.0% 0 / 13 Podpod 0.0% 0 / 8 totaltotal 0.0% 0 / 87 CC 7 SCAR 20.5
CC
7
Cov
0%
code
20.0
_parse_code
12.0
message
6.0
CRAP 7.8
1 use v5.10;
2 use strict;
3 use warnings;
4  
5 package Neo4j::Error::Server;
6 # ABSTRACT: Neo4j exception thrown by the Neo4j server
7 $Neo4j::Error::Server::VERSION = '0.01';
8  
9 use parent 'Neo4j::Error';
10  
11 use List::Util 1.33 qw(all);
12  
13  
14 sub source { 'Server' }
15  
16  
17 sub message {
18 my ($self) = @_;
19
20 # Decode "strict" Jolt format if necessary
21 $self->{message} = $self->{message}{U} if ref $self->{message} eq 'HASH';
22
23 return $self->{message} // '';
24 }
25  
26  
27 sub code {
28 my ($self) = @_;
29
30 # Decode "strict" Jolt format if necessary
31 $self->{code} = $self->{code}{U} if ref $self->{code} eq 'HASH';
32
33 return $self->{code} if defined $self->{code};
34
35 my @parts = (
36 'Neo',
37 $self->{classification},
38 $self->{category},
39 $self->{title},
40 );
41 return '' unless all { defined } @parts;
42 return $self->{code} = join '.', @parts;
43 }
44  
45  
46 sub _parse_code {
47 my ($self, $part) = @_;
48
49 return '' unless defined $self->{code};
50 my @parts = $self->{code} =~ m/^Neo\.([^\.]+)\.([^\.]+)\.(.+)$/i;
51 return '' unless @parts;
52
53 $self->{classification} = $parts[0];
54 $self->{category} = $parts[1];
55 $self->{title} = $parts[2];
56 return $self->{$part};
57 }
58  
59  
60 sub classification {
61 my ($self) = @_;
62
63 return $self->{classification} // $self->_parse_code('classification');
64 }
65  
66  
67 sub category {
68 my ($self) = @_;
69
70 return $self->{category} // $self->_parse_code('category');
71 }
72  
73  
74 sub title {
75 my ($self) = @_;
76
77 return $self->{title} // $self->_parse_code('title');
78 }
79  
80  
81 sub is_retryable {
82 my ($self) = @_;
83
84 return $self->classification eq 'TransientError';
85 }
86  
87  
88 1;