Subject: | overriding _exception_match_args |
Syntax::Feature::Try seems to have been on CPAN for a while now, but somehow I've only just noticed it. It seems very good. I'd like to use it to replace Try::Tiny in Moops (see https://metacpan.org/release/Moops for more info), however it has one missing feature before I can do that.
Moops provides syntactic sugar for OO programming in Moose, Mouse, or Moo. You don't have to choose just one - you can write one class with Moose, and one with Moo, and one with Mouse. Because each of these OO frameworks has different type constraint systems, I'd need _exception_match_args to behave differently based on the caller.
A simple implementation of the kind of thing I mean would be:
our %TYPE_HANDLER;
sub _exception_match_args {
my ($exception, $className) = @_;
return 1 if not defined $className; # without args catch all exceptions
my $caller = caller 2;
return $TYPE_HANDLER{$caller}->($caller, $exception, $className)
if $TYPE_HANDLER{$caller};
if (Moose::Util::TypeConstraints->can('find_type_constraint')) {
my $type = Moose::Util::TypeConstraints::find_type_constraint($className);
return $type->check($exception) if $type;
}
return blessed($exception) && $exception->isa($className);
}
Then I'd just have to ensure that Moops populated the %TYPE_HANDLER hash for each class it created.
That's not the only way of providing this feature, but it seems the easiest.
Whatever route you chose, I'd also need it to be officially documented, so I can be sure it's not going to disappear in the future.