Baldrick
Baldrick

Reputation: 11012

Installing Perl DateTime

When installing DateTime for Perl I get the following errors and it fails;

#   Failed test 'Make sure we can add 50 years worth of years in America/New_York time zone'
#   at t/30future-tz.t line 45.
Use of uninitialized value in numeric ge (>=) at /home/bensley/.cpan/build/DateTime-0.72/blib/lib/DateTime.pm line 138.

#   Failed test 'Make sure we can add 50 years worth of days in America/Chicago time zone'
#   at t/30future-tz.t line 45.
Use of uninitialized value in numeric ge (>=) at /home/bensley/.cpan/build/DateTime-0.72/blib/lib/DateTime.pm line 138.

#   Failed test 'Make sure we can add 50 years worth of minutes in America/Denver time zone'
#   at t/30future-tz.t line 45.
Use of uninitialized value in numeric ge (>=) at /home/bensley/.cpan/build/DateTime-0.72/blib/lib/DateTime.pm line 138.

#   Failed test 'Make sure we can add 50 years worth of seconds in America/Los_Angeles time zone'
#   at t/30future-tz.t line 45.
Use of uninitialized value in numeric ge (>=) at /home/bensley/.cpan/build/DateTime-0.72/blib/lib/DateTime.pm line 138.

#   Failed test 'Make sure we can add 50 years worth of nanoseconds in America/North_Dakota/Center time zone'
#   at t/30future-tz.t line 45.

The full output is quite long so I have pasted it here: http://pastebin.com/raw.php?i=JiJeH4ij

I'm new to Perl modules and thusly, completely lost. What's going on here?

UPDATE:

$ perl --version

This is perl, v5.8.8 built for i486-linux-gnu-thread-multi

$ lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description:    Ubuntu 8.04.4 LTS
Release:    8.04
Codename:   hardy

Upvotes: 3

Views: 6701

Answers (3)

parv
parv

Reputation: 21

Using a copy of the variable worked around the problem (perl 5.8.8, CentOS 5) ...

diff -ur DateTime-0.76/lib/DateTime.pm DateTime-0.76--perl-5.8.8.fix/lib/DateTime.pm
--- DateTime-0.76/lib/DateTime.pm.orig      2012-07-01 11:55:52.000000000 -1000
+++ DateTime-0.76/lib/DateTime.pm   2013-03-25 11:10:26.209878929 -1000
@@ -115,10 +115,17 @@
 __PACKAGE__->DefaultLocale('en_US');

 my $BasicValidate = {
+
+# XXX Mar 25 2013. Test t/30future-tz.t fails in versions 0.7[68], with perl
+# 5.8.8, with "Use of uninitialized value in numeric ge (>=) at [...] line 137."
+# See http://stackoverflow.com/questions/9601516/installing-perl-datetime for
+# other details. Apparently making a copy overcomes the problem of value
+# changing to undef (discovered by trial-and-error).
+
     year => {
         type      => SCALAR,
         callbacks => {
-            'is an integer' => sub { $_[0] =~ /^-?\d+$/ }
+            'is an integer' => sub { my $i = $_[0]; $i =~ /^-?\d+$/ }
         },
     },
     month => {
@@ -126,7 +133,7 @@
         default   => 1,
         callbacks => {
             'an integer between 1 and 12' =>
-                sub { $_[0] =~ /^\d+$/ && $_[0] >= 1 && $_[0] <= 12 }
+                sub { my $i = $_[0]; $i =~ /^\d+$/ && $i >= 1 && $i <= 12 }
         },
     },
     day => {
@@ -134,7 +141,7 @@
         default   => 1,
         callbacks => {
             'an integer which is a possible valid day of month' =>
-                sub { $_[0] =~ /^\d+$/ && $_[0] >= 1 && $_[0] <= 31 }
+                sub { my $i = $_[0]; $i =~ /^\d+$/ && $i >= 1 && $i <= 31 }
         },
     },
     hour => {
@@ -142,7 +149,7 @@
         default   => 0,
         callbacks => {
             'an integer between 0 and 23' =>
-                sub { $_[0] =~ /^\d+$/ && $_[0] >= 0 && $_[0] <= 23 },
+                sub { my $i = $_[0]; $i =~ /^\d+$/ && $i >= 0 && $i <= 23 },
         },
     },
     minute => {
@@ -150,7 +157,7 @@
         default   => 0,
         callbacks => {
             'an integer between 0 and 59' =>
-                sub { $_[0] =~ /^\d+$/ && $_[0] >= 0 && $_[0] <= 59 },
+                sub { my $i = $_[0]; $i =~ /^\d+$/ && $i >= 0 && $i <= 59 },
         },
     },
     second => {
@@ -158,14 +165,14 @@
         default   => 0,
         callbacks => {
             'an integer between 0 and 61' =>
-                sub { $_[0] =~ /^\d+$/ && $_[0] >= 0 && $_[0] <= 61 },
+                sub { my $i = $_[0]; $i =~ /^\d+$/ && $i >= 0 && $i <= 61 },
         },
     },
     nanosecond => {
         type      => SCALAR,
         default   => 0,
         callbacks => {
-            'a positive integer' => sub { $_[0] =~ /^\d+$/ && $_[0] >= 0 },
+            'a positive integer' => sub { my $i = $_[0]; $i =~ /^\d+$/ && $i >= 0 },
         }
     },
     locale => {

Upvotes: 2

adamlounds
adamlounds

Reputation: 101

Apologies for thread necromancy.

I had/have the same problem, installing on Centos 5.7, perl 5.8.8 (perl-5.8.8-38.el5). Annoyingly my browser window crashed with a whole pile more detail with Devel::Peek Dump()s.

Suffice to say that the m/^\d+$/ regex took the pPOK (same as POKp?) flag off and $_[0] became undef in both string and numeric contexts. I assume it's a bug in this specific version of perl as I can't reproduce on other OSes.

I ended up changing DateTime.pm to avoid the problem, as updating perl is not really an option at the moment:

129c129
<                 sub { $_[0] =~ /^\d+$/ && $_[0] >= 1 && $_[0] <= 12 }
---
>                 sub { $_[0] && $_[0] !~ /\D/ && $_[0] >= 1 && $_[0] <= 12 }
137c137
<                 sub { $_[0] =~ m/^\d+$/ && $_[0] >=1 && $_[0] <= 31 }
---
>                 sub { $_[0] && $_[0] !~ m/\D/ && $_[0] >=1 && $_[0] <= 31 }

Edit: found the Devel::Peek stuff in my buffer.

# generated by having this inside the validation sub
warn("before re (" . $_[0]. ")");
Dump($_[0])
return unless $_[0] =~ s/^\d+$/;
warn("after re (" . $_[0] . ")");
Dump($_[0]);

output:

before re (1) at blib/lib/DateTime.pm line 139.
SV = PVMG(0x8104d40) at 0x827dc24
REFCNT = 7
FLAGS = (GMG,SMG,READONLY,pPOK)
IV = 0
NV = 0
PV = 0x8502610 "1"\0
CUR = 1
LEN = 4
MAGIC = 0x82d9a30
    MG_VIRTUAL = &PL_vtbl_sv
    MG_TYPE = PERL_MAGIC_sv(\0)
    MG_OBJ = 0x827dc18
    MG_LEN = 1
    MG_PTR = 0x82d9a50 "3"
Use of uninitialized value in concatenation (.) or string at blib/lib/DateTime.pm line 142.
after re () at blib/lib/DateTime.pm line 142.
SV = PVMG(0x8104d40) at 0x827dc24
REFCNT = 7
FLAGS = (GMG,SMG,READONLY)
IV = 0
NV = 0
PV = 0x8502610 "1"\0
CUR = 1
LEN = 4
MAGIC = 0x82d9a30
    MG_VIRTUAL = &PL_vtbl_sv
    MG_TYPE = PERL_MAGIC_sv(\0)
    MG_OBJ = 0x827dc18
    MG_LEN = 1
    MG_PTR = 0x82d9a50 "3"
Use of uninitialized value in numeric ge (>=) at blib/lib/DateTime.pm line 144.
not ok 1 - Make sure we can add 50 years worth of years in America/New_York time zone
#   Failed test 'Make sure we can add 50 years worth of years in America/New_York time zone'
#   at t/30future-tz.t line 45.

Upvotes: 2

Schwern
Schwern

Reputation: 165396

This is likely your problem.

Package seems to come without Makefile.PL.
  (The test -f "/home/bensley/.cpan/build/DateTime-0.72/Makefile.PL" returned false.)
  Writing one on our own (setting NAME to DateTime)

Your copy of the CPAN client is so out of date it does not recognize the "new" (by which I mean 10 years old) Build.PL module build and install mechanism. CPAN instead wrote its own installer and tried to do the installation anyway. This will work for many Perl modules, but it probably missed some subtlety required by DateTime.

Upgrade the CPAN client, you can do it with the CPAN client, and then try again.

Upvotes: 9

Related Questions