blib/lib/Beekeeper/JSONRPC/Error.pm untested

filter: Statementstmt 0.0% 0 / 31 Branchbran n/a Conditioncond 0.0% 0 / 4 MC/DCmcdc n/a Subroutinesub 0.0% 0 / 20 Podpod 0.0% 0 / 17 totaltotal 0.0% 0 / 72 SCAR 6.9
CC
1
Cov
0%
new
2.0
id
2.0
message
2.0
CRAP 2.0
1 package Beekeeper::JSONRPC::Error;
2  
3 use strict;
4 use warnings;
5  
6 our $VERSION = '0.09';
7  
8  
9 use overload '""' => sub { $_[0]->{error}->{message} };
10  
11 sub new {
12 my ($class, %args) = @_;
13  
14 bless {
15 jsonrpc => '2.0',
16 id => undef,
17 error => {
18 code => $args{code} || -32603,
19 message => $args{message} || "Internal error",
20 data => $args{data},
21 },
22 }, $class;
23 }
24  
25 sub id { $_[0]->{id} }
26 sub message { $_[0]->{error}->{message} }
27 sub code { $_[0]->{error}->{code} }
28 sub data { $_[0]->{error}->{data} }
29  
30 sub success { 0 }
31  
32 sub TO_JSON { return { %{$_[0]} } }
33  
34  
35 sub parse_error {
36 shift->new(
37 code => -32700,
38 message => "Parse error",
39 data => "Invalid JSON was received by the server",
40 @_
41 );
42 }
43  
44 sub invalid_request {
45 shift->new(
46 code => -32600,
47 message => "Invalid request",
48 data => "The JSON sent is not a valid request object.",
49 @_
50 );
51 }
52  
53 sub request_timeout {
54 shift->new(
55 code => -31600,
56 message => "Request timeout",
57 @_
58 );
59 }
60  
61 sub request_not_authenticated {
62 shift->new(
63 code => -401,
64 message => "Not logged in",
65 data => "Request was not authenticated",
66 @_
67 );
68 }
69  
70 sub request_not_authorized {
71 shift->new(
72 code => -403,
73 message => "Request not authorized",
74 data => "Request was not authorized",
75 @_
76 );
77 }
78  
79 sub method_not_found {
80 shift->new(
81 code => -32601,
82 message => "Method not found",
83 data => "The method does not exist",
84 @_
85 );
86 }
87  
88 sub method_not_available {
89 shift->new(
90 code => -31601,
91 message => "Method not available",
92 data => "The method is not available.",
93 @_
94 );
95 }
96  
97 sub invalid_params {
98 shift->new(
99 code => -32602,
100 message => "Invalid params",
101 data => "Invalid method parameters.",
102 @_
103 );
104 }
105  
106 sub internal_error {
107 shift->new(
108 code => -32603,
109 message => "Internal error",
110 data => "Internal JSON-RPC error.",
111 @_
112 );
113 }
114  
115 sub server_error {
116 shift->new(
117 code => -32000,
118 message => "Server error",
119 @_
120 );
121 }
122  
123 1;
124  
125 __END__