develooper Front page | perl.perl5.porters | Postings from July 2018

Re: [perl #133357] Time::Piece overloading will not acceptoverloaded objects

Thread Previous
From:
Dan Book
Date:
July 13, 2018 04:05
Subject:
Re: [perl #133357] Time::Piece overloading will not acceptoverloaded objects
Message ID:
17282_1531454735_5B48250F_17282_23_1_CABMkAVXa4wdw1oLcgmMd4c-b2qbb9bgRJJ0dH46waTCdOR=X7g@mail.gmail.com
On Thu, Jul 12, 2018 at 11:38 PM Maurice Aubrey <maurice.aubrey@gmail.com>
wrote:

>
> I have a proof-of-concept here:
>
> https://github.com/Dual-Life/Time-Piece/compare/master...mla:feature/blessed?expand=1
>
> It's using Scalar::Util, which I'm not sure is okay or not for a core
> module. But it's still passing all tests and satisfies my use case.
>

I don't think we need looks_like_number or reftype here either. reftype
will violate the encapsulation of an object that's passed, you should only
check that if it's not blessed (in which case you can just just check if
ref eq 'ARRAY'). The looks_like_number check shouldn't be necessary
(looks_like_number has some interesting edge cases), you can just use it as
a number and depend on appropriate overloading, Perl will emit the
appropriate warning or error if it doesn't end up being numeric.
Time::Seconds's overload means we don't need to special case that as you
correctly fixed.

-Dan

Thread Previous


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About