p5pclub / ref-util

Ref::Util - Utility functions for checking references
6 stars 11 forks source link

Deref sugar #47

Open grr opened 1 year ago

grr commented 1 year ago

This is the converse of #43 . Instead of creating refs, I want to make it easier to deref as in this idiom:

my $ref = [qw(header1 val1 header2 val2)];
#my $ref = {qw(header1 val1 header2 val2)};
my @list = is_hashref $ref ? %$ref : is_arrayref $ref ? @$ref : $ref;

# want:
my @list = deref $ref;

This could be useful in implementing a method like URI's query_form(), which can take a list, hashref or arrayref of key/vals.

grr commented 1 year ago

Found a similar old request in the RT queue of Scalar-List-Utils: https://rt.cpan.org/Public/Bug/Display.html?id=105290