| 1 | package CSAF::Validator::Message; | ||
| 2 | |||
| 3 | use 5.010001; | ||
| 4 | use strict; | ||
| 5 | use warnings; | ||
| 6 | use utf8; | ||
| 7 | |||
| 8 | use Moo; | ||
| 9 | |||
| 10 | use overload '""' => \&to_string, bool => sub {1}, fallback => 1; | ||
| 11 | |||
| 12 | has message => (is => 'ro', required => 1); | ||
| 13 | has code => (is => 'ro'); | ||
| 14 | has path => (is => 'ro'); | ||
| 15 | has type => (is => 'ro', default => 'error'); | ||
| 16 | has category => (is => 'ro', required => 1); | ||
| 17 | |||
| 18 | sub to_string { | ||
| 19 | sprintf '[%s] %s: %s (%s - %s)', $_[0]->type, $_[0]->path, $_[0]->message, $_[0]->code, $_[0]->category; | ||
| 20 | } | ||
| 21 | |||
| 22 | sub TO_JSON { | ||
| 23 | |||
| 24 | return { | ||
| 25 | type => $_[0]->type, | ||
| 26 | category => $_[0]->category, | ||
| 27 | message => $_[0]->message, | ||
| 28 | path => $_[0]->path, | ||
| 29 | code => $_[0]->code | ||
| 30 | }; | ||
| 31 | |||
| 32 | } | ||
| 33 | |||
| 34 | 1; | ||
| 35 | |||
| 36 | __END__ |