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

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

Thread Previous | Thread Next
From:
Maurice Aubrey
Date:
July 13, 2018 03:31
Subject:
Re: [perl #133357] Time::Piece overloading will not acceptoverloaded objects
Message ID:
15198_1531265116_5B45405C_15198_100_1_CAMjjn=E1TkfiYKsbh6y1u+U46C0OtdhOwiaHF2tgkZ+=nBJ2VQ@mail.gmail.com
On Tue, Jul 10, 2018 at 3:47 PM Dan Book via RT <perlbug-followup@perl.org>
wrote:

> On Tue, Jul 10, 2018 at 6:40 PM Samuel Smith <p5p@net153.net> wrote:
>
> >
> > I am not familiar with 'bignum' either. I'd be curious to see how other
> > module authors handle a case when a native perl data type (Integer) is
> > suddenly converted into a class... Seems kind of messy.
> >
> > You can certainly stringify your bignum ref to force a non-ref output as
> > well such as: $d2 = $d1 + "$secs";
> >
> >
> It shouldn't be that messy. It just needs to distinguish blessed objects
> that *aren't* the expected class, and pretend they are a number so they
> overload appropriately. Only unblessed refs should trigger the error.
>

Yes, that was my thought. I'll move this to the dual-life github, thanks.

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.

Maurice



>
> -Dan
>
>

Thread Previous | Thread Next


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