Simplify/FieldError.pm untested

filter: Statementstmt 0.0% 0 / 29 Branchbran n/a Conditioncond n/a MC/DCmcdc n/a Subroutinesub 0.0% 0 / 9 Podpod 0.0% 0 / 5 totaltotal 0.0% 0 / 43 CC 1 SCAR 6.9
CC
1
Cov
0%
new
2.0
field
2.0
code
2.0
CRAP 2.0
1  
2 package Net::Simplify::FieldError;
3  
4  
5 =head1 NAME
6  
7 Net::Simplify::FieldError - Simplify Commerce field error class
8  
9 =head1 SYNOPSIS
10  
11 use Net::Simplify;
12  
13 $Net::Simplify::public_key = 'YOUR PUBLIC KEY';
14 $Net::Simplify::private_key = 'YOUR PRIVATE KEY';
15  
16 eval {
17 my $payment = Net::Simplify::Payment->create(...);
18 };
19 if ($@) {
20 if ($@->isa('Net::Simplify::BadRequestException')) {
21 if ($@->has_field_errors) {
22 foreach my $error ($@->field_errors) {
23 my $c = $error->code;
24 my $f = $error->field;
25 my $m = $error->message;
26 printf "Field error: %s - '%s' (%s)\n", $f, $m, $c;
27 }
28 }
29 }
30 }
31
32 =head1 DESCRIPTION
33  
34 Represents a single error in an API request to create or update a domain object.
35  
36 =head2 METHODS
37  
38 =head3 field()
39  
40 The name of the field with the error.
41  
42 =head3 code()
43  
44 The field error code.
45  
46 =head3 message()
47  
48 A textual description of the error.
49  
50 =head3 stringify()
51  
52 A string representation of the field error.
53  
54 =head1 SEE ALSO
55  
56 L<Net::Simplify>,
57 L<Net::Simplify::BadRequestException>,
58 L<http://www.simplify.com>
59  
60 =head1 VERSION
61  
62 1.6.0
63  
64 =head1 LICENSE
65  
66 Copyright (c) 2013 - 2022 MasterCard International Incorporated
67 All rights reserved.
68  
69 Redistribution and use in source and binary forms, with or without modification, are
70 permitted provided that the following conditions are met:
71  
72 Redistributions of source code must retain the above copyright notice, this list of
73 conditions and the following disclaimer.
74 Redistributions in binary form must reproduce the above copyright notice, this list of
75 conditions and the following disclaimer in the documentation and/or other materials
76 provided with the distribution.
77 Neither the name of the MasterCard International Incorporated nor the names of its
78 contributors may be used to endorse or promote products derived from this software
79 without specific prior written permission.
80 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
81 EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
82 OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
83 SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
84 INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
85 TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
86 OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
87 IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
88 IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
89 SUCH DAMAGE.
90  
91 =cut
92  
93 use 5.006;
94 use strict;
95 use warnings FATAL => 'all';
96  
97 use overload ('""' => 'stringify');
98  
99 sub new {
100 my ($class, $params) = @_;
101  
102 my $self = {};
103  
104 $self->{field} = $params->{field};
105 $self->{code} = $params->{code};
106 $self->{message} = $params->{message};
107  
108 bless $self, $class;
109 }
110  
111 sub field {
112 my ($self) = @_;
113  
114 $self->{field};
115 }
116  
117 sub code {
118 my ($self) = @_;
119  
120 $self->{code};
121 }
122 sub message {
123 my ($self) = @_;
124  
125 $self->{message};
126 }
127  
128 sub stringify {
129 my ($self) = @_;
130  
131 my $code = $self->{code};
132 my $field = $self->{field};
133 my $message = $self->{message};
134  
135 qq|Field error: ${field} "${message}" (${code})\n|;
136 }
137  
138  
139 1;