Subject: | Return values from callbacks |
Currently it seems that callbacks may only be used to throw exceptions.
There's no way to use a callback to "repair" a value. This can be easily
be fixed if changing calls like
$self->{callback}->{retrieve_key_from_non_hash}->($data, $key,
$index, $value, $rest);
to
$value = $self->{callback}->{retrieve_key_from_non_hash}->($data,
$key, $index, $value, $rest);
in a couple of places in Data/Path.pm.
Rationale for this request: in the present version of Data::Path it is
difficult to deal with blessed hash-based objects which except to be
accessed directly without accessor methods. Data::Path checks the type
using ref ... eq "HASH" which fails for such objects. Using callbacks
the user could "repair" the return value by specifying a callback like this.
retrieve_key_from_non_hash => sub {
my($data, $key) = @_;
$_[3] = $data->{$key};
},
}
Another approach could be to use Scalar::Util::reftype instead of ref
for such checks. reftype would return HASH for blessed HASH-based objects.
Regards,
Slaven