my $WARNINGS_CATEGORY;
BEGIN {
$WARNINGS_CATEGORY = 'File::KDBX';
- warnings::register_categories($WARNINGS_CATEGORY) if warnings->can('register_categories');
+ if (warnings->can('register_categories')) {
+ warnings::register_categories($WARNINGS_CATEGORY);
+ }
+ else {
+ eval qq{package $WARNINGS_CATEGORY; use warnings::register; 1}; ## no critic ProhibitStringyEval
+ }
}
use overload '""' => 'to_string', cmp => '_cmp';
This can be convenient for error handling when you're not sure what the exception is but you want to treat it
as a B<File::KDBX::Error>. Example:
- eval { .... };
+ eval { ... };
if (my $error = error(@_)) {
if ($error->type eq 'key.missing') {
handle_missing_key($error);