Skip Menu |

This queue is for tickets about the Data-Path CPAN distribution.

Report information
The Basics
Id: 32912
Status: open
Priority: 0/
Queue: Data-Path

People
Owner: Nobody in particular
Requestors: SREZIC [...] cpan.org
Cc:
AdminCc:

Bug Information
Severity: Wishlist
Broken in: 1.1
Fixed in: (no value)



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
I'm considering this possiblity. But I'm curious why would you have objects without a well defined interface to get data from them? I'm on the fence as to the value of this one. On Mon Feb 04 07:59:08 2008, SREZIC wrote: Show quoted text
> 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. Show quoted text
> > 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
On Wed Feb 20 22:28:11 2008, ZAPHAR wrote: Show quoted text
> I'm considering this possiblity. But I'm curious why would you have > objects without a well defined interface to get data from them?
Well, that's Perl giving me the possibility to do it like this. Unfortunately I cannot remember where I wanted to use this feature, so I cannot give a detailed explanation for this. So feel free to reject this ticket. Regards, Slaven Show quoted text
> I'm on > the fence as to the value of this one. > > On Mon Feb 04 07:59:08 2008, SREZIC wrote:
> > 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. Show quoted text
> > > > Regards, > > Slaven
> >