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

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

Thread Next
July 13, 2018 03:30
[perl #133357] Time::Piece overloading will not accept overloadedobjects
Message ID:
# New Ticket Created by   
# Please include the string:  [perl #133357]
# in the subject line of all future correspondence about this issue. 
# <URL: >

This is a bug report for perl from,
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.


  #!/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.

[Please do not change anything below this line]
Site configuration information for perl 5.18.2:

Configured by mla at Mon Apr 16 13:43:46 PDT 2018.

Summary of my perl5 (revision 5 version 18 subversion 2) configuration:
    osname=linux, osvers=4.10.0-38-generic, archname=x86_64-linux
    uname='linux yoda 4.10.0-38-generic #42~16.04.1-ubuntu smp tue oct 10 16:32:20 utc 2017 x86_64 x86_64 x86_64 gnulinux '
    config_args='-Dprefix=/home/mla/.plenv/versions/5.18.2 -de -Dversiononly -Duseshrplib -A'eval:scriptdir=/home/mla/.plenv/versions/5.18.2/bin''
    hint=recommended, useposix=true, d_sigaction=define
    useithreads=undef, usemultiplicity=undef
    useperlio=define, d_sfio=undef, uselargefiles=define, usesocks=undef
    use64bitint=define, use64bitall=define, uselongdouble=undef
    usemymalloc=n, bincompat5005=undef
    cc='cc', ccflags ='-fno-strict-aliasing -pipe -fstack-protector -I/usr/local/include -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64',
    cppflags='-fno-strict-aliasing -pipe -fstack-protector -I/usr/local/include'
    ccversion='', gccversion='5.4.0 20160609', gccosandvers=''
    intsize=4, longsize=8, ptrsize=8, doublesize=8, byteorder=12345678
    d_longlong=define, longlongsize=8, d_longdbl=define, longdblsize=16
    ivtype='long', ivsize=8, nvtype='double', nvsize=8, Off_t='off_t', lseeksize=8
    alignbytes=8, prototype=define
  Linker and Libraries:
    ld='cc', ldflags =' -fstack-protector -L/usr/local/lib'
    libpth=/usr/local/lib /lib/x86_64-linux-gnu /lib/../lib /usr/lib/x86_64-linux-gnu /usr/lib/../lib /lib /usr/lib
    libs=-lnsl -ldl -lm -lcrypt -lutil -lc
    perllibs=-lnsl -ldl -lm -lcrypt -lutil -lc, so=so, useshrplib=true,
  Dynamic Linking:
    dlsrc=dl_dlopen.xs, dlext=so, d_dlsymun=undef, ccdlflags='-Wl,-E -Wl,-rpath,/home/mla/.plenv/versions/5.18.2/lib/perl5/5.18.2/x86_64-linux/CORE'
    cccdlflags='-fPIC', lddlflags='-shared -O2 -L/usr/local/lib -fstack-protector'

Locally applied patches:
    Devel::PatchPerl 1.48

@INC for perl 5.18.2:

Environment for perl 5.18.2:
    LD_LIBRARY_PATH (unset)
    LOGDIR (unset)
    PERL_BADLANG (unset)

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