develooper Front page | perl.perl5.porters | Postings from December 2015

Re: Proposal: Add {-as => 'new_name'} feature to

Thread Previous | Thread Next
December 18, 2015 10:49
Re: Proposal: Add {-as => 'new_name'} feature to
Message ID:
On Fri, Dec 18, 2015 at 02:15:09AM +0100, Lukas Mai wrote:
> Am 18.12.2015 um 01:39 schrieb demerphq:
>> On 18 December 2015 at 00:14, Chad Granum <> wrote:
>>> new patch
>>> On Thu, Dec 17, 2015 at 2:57 PM, Chad Granum <> wrote:
>>>> No sooner did I send that then I realize did could do it better with 1
>>>> less loop. Will attach new patch shortly.
>> I have one concern with the patch. It uses ref($foo) eq "HASH".
>> I think it should import reftype() from Scalar::Util and use reftype() instead.
>> Or possibly be switched to use UNIVERSAL::isa($foo,"HASH").
>> IOW, what happens if $foo is blessed?
> reftype is for deliberately breaking encapsulation of objects. I'd  
> prefer if Exporter stringified objects or just didn't accept them.

It already stringifies objects (which is to be expected, as it treats
all its arguments as strings):

    use strict;
    use warnings;

    package Fnord;

    use overload '""' => sub {"max"};

    use List::Util 'min', bless {-as => "max"} => "Fnord";

    my $m = max (1, 3, 2);   # List::Util::max

    say $m;


So, the proposed syntax could, in theory, break existing code.
But the breakable code is, IMO, weird enough to not worry about.


Thread Previous | Thread Next Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About