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

[perl #133357] Time::Piece overloading will not accept overloadedobjects

Thread Previous | Thread Next
From:
James E Keenan via RT
Date:
July 10, 2018 21:33
Subject:
[perl #133357] Time::Piece overloading will not accept overloadedobjects
Message ID:
rt-4.0.24-11927-1531258389-921.133357-15-0@perl.org
On Tue, 10 Jul 2018 20:19:39 GMT, maurice.aubrey@gmail.com wrote:
> 
> This is a bug report for perl from maurice.aubrey@gmail.com,
> generated with the help of perlbug 1.39 running under perl 5.18.2.
> 
> 
> -----------------------------------------------------------------
> [Please describe your issue here]
> 
> Discovered that bignum does not play nice with Time::Piece.
> Getting "Invalid rhs of addition: 46800" errors when the seconds
> value is a Math::BigInt::Lite instance.
> 
> Example:
> 
> #!/usr/bin/env perl
> 
> use strict;
> use warnings;
> use Time::Piece qw/ localtime /;
> use Time::Seconds;
> 
> my $d1 = localtime;
> print "\$d1 is a ", ref($d1), "\n";
> 
> my $secs = 46800;
> print "\$secs is a ", (ref($secs) || 'scalar') , "\n";
> 
> my $d2 = $d1 + $secs;
> print "sum is: $d2\n\n";
> 
> use bignum;
> 
> $secs = 46800;
> print "\$secs is a ", (ref($secs) || 'scalar') , "\n";
> 
> $d2 = $d1 + $secs;
> print "sum is: $d2\n";
> 
> 
> There's an explicit check for a ref on rhs, in which case the value
> is rejected. From Time::Piece 1.3204:
> 
> sub add {
>     my $time = shift;
>     my $rhs = shift;
>     if (UNIVERSAL::isa($rhs, 'Time::Seconds')) {
>         $rhs = $rhs->seconds;
>     }
>     croak "Invalid rhs of addition: $rhs" if ref($rhs);
> 
> return $time->_mktime(($time->epoch + $rhs), $time->[c_islocal]);
> }
> 
> Just removing the ref check isn't enough. There's also a problem with
> _mktime
> if $time is a blessed ref (it assumes it's an array ref currently).
> 
> Can manually create a Time::Seconds instance and force the BigInt to a
> scalar,
> of course, but would be nice if it was transparent.
> 
> Didn't see a repo published to discuss this module. Let me know if I
> should
> direct this elsewhere.
> 

According to Porting/Maintainers.pl, Time-Piece is maintained upstream on CPAN:

https://metacpan.org/release/Time-Piece

Its bug tracker is here:

https://rt.cpan.org/Dist/Display.html?Name=Time-Piece

So please file this report at that URL or send email to:

bug-Time-Piece@rt.cpan.org

Thank you very much.
-- 
James E Keenan (jkeenan@cpan.org)

---
via perlbug:  queue: perl5 status: new
https://rt.perl.org/Ticket/Display.html?id=133357

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