| 1 | package SQL::Validator::Error; | ||
| 2 | |||
| 3 | use 5.014; | ||
| 4 | |||
| 5 | use strict; | ||
| 6 | use warnings; | ||
| 7 | |||
| 8 | use registry; | ||
| 9 | use routines; | ||
| 10 | |||
| 11 | use Data::Object::Class; | ||
| 12 | use Data::Object::ClassHas; | ||
| 13 | |||
| 14 | extends 'Data::Object::Exception'; | ||
| 15 | |||
| 16 | our $VERSION = '0.01'; # VERSION | ||
| 17 | |||
| 18 | # ATTRIBUTES | ||
| 19 | |||
| 20 | has 'issues' => ( | ||
| 21 | is => 'ro', | ||
| 22 | isa => 'ArrayRef[InstanceOf["JSON::Validator::Error"]]', | ||
| 23 | req => 1, | ||
| 24 | ); | ||
| 25 | |||
| 26 | # METHODS | ||
| 27 | |||
| 28 | method match(Str $key = '/') { | ||
| 29 | $key =~ s/^\/*/\//; | ||
| 30 | |||
| 31 | my @matches = grep {$_->path =~ /^$key/} @{$self->issues}; | ||
| 32 | |||
| 33 | return [@matches]; | ||
| 34 | } | ||
| 35 | |||
| 36 | method report(Str $key = '/') { | ||
| 37 | my $matches = $self->match($key); | ||
| 38 | |||
| 39 | return join "\n", sort map "$_", @$matches; | ||
| 40 | } | ||
| 41 | |||
| 42 | 1; | ||
| 43 | =encoding utf8 | ||
| 44 | |||
| 45 | =head1 NAME | ||
| 46 | |||
| 47 | SQL::Validator::Error - JSON-SQL Schema Validation Error | ||
| 48 | |||
| 49 | =cut | ||
| 50 | |||
| 51 | =head1 ABSTRACT | ||
| 52 | |||
| 53 | JSON-SQL Schema Validation Error | ||
| 54 | |||
| 55 | =cut | ||
| 56 | |||
| 57 | =head1 SYNOPSIS | ||
| 58 | |||
| 59 | use SQL::Validator::Error; | ||
| 60 | use JSON::Validator::Error; | ||
| 61 | |||
| 62 | my $error = SQL::Validator::Error->new( | ||
| 63 | issues => [ | ||
| 64 | JSON::Validator::Error->new('/root', 'not okay'), | ||
| 65 | JSON::Validator::Error->new('/node/0', 'not okay'), | ||
| 66 | JSON::Validator::Error->new('/node/1', 'not okay') | ||
| 67 | ] | ||
| 68 | ); | ||
| 69 | |||
| 70 | =cut | ||
| 71 | |||
| 72 | =head1 DESCRIPTION | ||
| 73 | |||
| 74 | This package provides a class representation of a error resulting from the | ||
| 75 | validation of JSON-SQL schemas. | ||
| 76 | |||
| 77 | =cut | ||
| 78 | |||
| 79 | =head1 INHERITS | ||
| 80 | |||
| 81 | This package inherits behaviors from: | ||
| 82 | |||
| 83 | L<Data::Object::Exception> | ||
| 84 | |||
| 85 | =cut | ||
| 86 | |||
| 87 | =head1 ATTRIBUTES | ||
| 88 | |||
| 89 | This package has the following attributes: | ||
| 90 | |||
| 91 | =cut | ||
| 92 | |||
| 93 | =head2 issues | ||
| 94 | |||
| 95 | issues(ArrayRef[InstanceOf["JSON::Validator::Error"]]) | ||
| 96 | |||
| 97 | This attribute is read-only, accepts C<(ArrayRef[InstanceOf["JSON::Validator::Error"]])> values, and is required. | ||
| 98 | |||
| 99 | =cut | ||
| 100 | |||
| 101 | =head1 METHODS | ||
| 102 | |||
| 103 | This package implements the following methods: | ||
| 104 | |||
| 105 | =cut | ||
| 106 | |||
| 107 | =head2 match | ||
| 108 | |||
| 109 | match(Str $key = '/') : ArrayRef[Object] | ||
| 110 | |||
| 111 | The match method returns the matching issues as an error string. | ||
| 112 | |||
| 113 | =over 4 | ||
| 114 | |||
| 115 | =item match example #1 | ||
| 116 | |||
| 117 | # given: synopsis | ||
| 118 | |||
| 119 | my $root = $error->match('root'); | ||
| 120 | |||
| 121 | =back | ||
| 122 | |||
| 123 | =over 4 | ||
| 124 | |||
| 125 | =item match example #2 | ||
| 126 | |||
| 127 | # given: synopsis | ||
| 128 | |||
| 129 | my $nodes = $error->match('node'); | ||
| 130 | |||
| 131 | =back | ||
| 132 | |||
| 133 | =cut | ||
| 134 | |||
| 135 | =head2 report | ||
| 136 | |||
| 137 | report(Str $key = '/') : Str | ||
| 138 | |||
| 139 | The report method returns the reporting issues as an error string. | ||
| 140 | |||
| 141 | =over 4 | ||
| 142 | |||
| 143 | =item report example #1 | ||
| 144 | |||
| 145 | # given: synopsis | ||
| 146 | |||
| 147 | my $report = $error->report('root'); | ||
| 148 | |||
| 149 | =back | ||
| 150 | |||
| 151 | =over 4 | ||
| 152 | |||
| 153 | =item report example #2 | ||
| 154 | |||
| 155 | # given: synopsis | ||
| 156 | |||
| 157 | my $report = $error->report('node'); | ||
| 158 | |||
| 159 | =back | ||
| 160 | |||
| 161 | =cut | ||
| 162 | |||
| 163 | =head1 AUTHOR | ||
| 164 | |||
| 165 | Al Newkirk, C<awncorp@cpan.org> | ||
| 166 | |||
| 167 | =head1 LICENSE | ||
| 168 | |||
| 169 | Copyright (C) 2011-2019, Al Newkirk, et al. | ||
| 170 | |||
| 171 | This is free software; you can redistribute it and/or modify it under the terms | ||
| 172 | of the The Apache License, Version 2.0, as elucidated in the L<"license | ||
| 173 | file"|https://github.com/iamalnewkirk/sql-validator/blob/master/LICENSE>. | ||
| 174 | |||
| 175 | =head1 PROJECT | ||
| 176 | |||
| 177 | L<Wiki|https://github.com/iamalnewkirk/sql-validator/wiki> | ||
| 178 | |||
| 179 | L<Project|https://github.com/iamalnewkirk/sql-validator> | ||
| 180 | |||
| 181 | L<Initiatives|https://github.com/iamalnewkirk/sql-validator/projects> | ||
| 182 | |||
| 183 | L<Milestones|https://github.com/iamalnewkirk/sql-validator/milestones> | ||
| 184 | |||
| 185 | L<Contributing|https://github.com/iamalnewkirk/sql-validator/blob/master/CONTRIBUTE.md> | ||
| 186 | |||
| 187 | L<Issues|https://github.com/iamalnewkirk/sql-validator/issues> | ||
| 188 | |||
| 189 | =cut |