App-Actions
view release on metacpan or search on metacpan
lib/App/Actions/Schema/Invalid.pm view on Meta::CPAN
package App::Actions::Schema::Invalid;
use strict;
use warnings;
# An App::Actions::Error with the code schema.invalid, so a caller can ask
# either "is it an Invalid?" or "is it the error schema.invalid?". It reports
# a document rather than a place in the code, so it has no location, and the
# message is the whole text, which keeps message and stringification equal.
use parent 'App::Actions::Error';
our $VERSION = '0.002.1';
sub new {
my ($class, $message) = @_;
return $class->SUPER::new(code => 'schema.invalid', message => $message, location => '');
}
1;
__END__
=encoding utf-8
=head1 NAME
App::Actions::Schema::Invalid - the error for a document that does not match its schema
=head1 SYNOPSIS
Catch it after a check:
use App::Actions::Schema qw(assert_valid);
eval { assert_valid($document, $schema, 'the report does not match its schema'); 1 }
or do {
my $error = $@;
if (ref $error && $error->isa('App::Actions::Schema::Invalid')) {
print STDERR $error->message;
exit App::Actions::Schema::invalid_exit();
}
die $error;
};
Ask by code, as for any App::Actions::Error:
if (my $error = App::Actions::Error->caught($@)) {
exit 70 if $error->is('schema.invalid');
}
Throw one yourself:
die App::Actions::Schema::Invalid->new("my document: \$.name: missing\n");
=head1 DESCRIPTION
L<App::Actions::Schema/assert_valid> throws this object when a document does
not match its schema. It is an L<App::Actions::Error>, so it has every
method that class has. Three things are always the same:
=over 4
=item * its code is C<schema.invalid>;
=item * its location is empty, because the problem is in a document, not at
a place in the program;
=item * so, as a string, it is exactly its message, with the newline at the
end if the message has one. C<die> and C<warn> print it unchanged.
=back
=head1 METHODS
=head2 new
( run in 1.196 second using v1.01-cache-2.11-cpan-4e491c91c6e )