JsonSQL::Error - Defines an error object to be used at various stages of JSON validation and SQL generation.
version 0.4
To use this:
return JsonSQL::Error->new(<error_type>, <error_msg>);
To check return values for errors:
my $retval = myFunc(); if ( eval { $retval->is_error } ) { return "An error occurred: $retval->{message}"; } else { ... }
This module was inspired by Brian D Foy's post on The Effective Perler, https://www.effectiveperlprogramming.com/2011/10/return-error-objects-instead-of-throwing-exceptions/
Instantiates and returns a new JsonSQL::Error object.
$type => Any string to group error messages by. $message => The error message.
Returns a true value. Used for conveniently catching errors:
if ( eval { $result->is_error } ) { die $result->{message}; }
Returns the type property. Useful for adding for/when loops to error handlers:
for ( $result->type ) { when ( 'validate' ) { $err = "JSON schema validation error: <br />"; $err .= "$result->{message} <br />"; $err =~ s/\n/\<br \/\>/; } default { $err = "An unspecified error occurred. <br />"; } }
Stringifies the error object and returns it.
Chris Hoefler <bhoefler@draper.com>
This software is copyright (c) 2017 by Chris Hoefler.
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.
To install JsonSQL, copy and paste the appropriate command in to your terminal.
cpanm
cpanm JsonSQL
CPAN shell
perl -MCPAN -e shell install JsonSQL
For more information on module installation, please visit the detailed CPAN module installation guide.