1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83
|
package JSON::Validator::Error;
use Mojo::Base -base;
use overload q("") => \&to_string, bool => sub {1}, fallback => 1;
sub new {
my $self = bless {}, shift;
@$self{qw(path message)} = ($_[0] || '/', $_[1] || '');
$self;
}
sub message { shift->{message} }
sub path { shift->{path} }
sub to_string { sprintf '%s: %s', @{$_[0]}{qw(path message)} }
sub TO_JSON { {message => $_[0]->{message}, path => $_[0]->{path}} }
1;
=encoding utf8
=head1 NAME
JSON::Validator::Error - JSON::Validator error object
=head1 SYNOPSIS
use JSON::Validator::Error;
my $err = JSON::Validator::Error->new($path, $message);
=head1 DESCRIPTION
L<JSON::Validator::Error> is a class representing validation errors from
L<JSON::Validator>.
=head1 ATTRIBUTES
=head2 message
my $str = $error->message;
A human readable description of the error. Defaults to empty string.
=head2 path
my $str = $error->path;
A JSON pointer to where the error occurred. Defaults to "/".
=head1 METHODS
=head2 new
my $error = JSON::Validator::Error->new($path, $message);
Object constructor.
=head2 to_string
my $str = $error->to_string;
Returns the "path" and "message" part as a string: "$path: $message".
=head1 OPERATORS
L<JSON::Validator::Error> overloads the following operators:
=head2 bool
my $bool = !!$error;
Always true.
=head2 stringify
my $str = "$error";
Alias for L</to_string>.
=head1 SEE ALSO
L<JSON::Validator>.
=cut
|