File: Error.pm

package info (click to toggle)
libjson-validator-perl 0.92%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 408 kB
  • ctags: 89
  • sloc: perl: 1,009; makefile: 6
file content (63 lines) | stat: -rw-r--r-- 1,106 bytes parent folder | download
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
package JSON::Validator::Error;
use Mojo::Base -base;

use overload
  q("")    => sub { sprintf '%s: %s', @{$_[0]}{qw(path message)} },
  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_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

  $str = $self->message;

A human readable description of the error. Defaults to empty string.

=head2 path

  $str = $self->path;

A JSON pointer to where the error occurred. Defaults to "/".

=head1 METHODS

=head2 new

  $self = JSON::Validator::Error->new($path, $message);

Object constructor.

=head1 SEE ALSO

L<JSON::Validator>.

=cut