Setting Perl DateTime
When installing DateTime for Perl, I get the following errors and fail:
# 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 pasted it here: http://pastebin.com/raw.php?i=JiJeH4ij
I am new to Perl modules and thus 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
source to share
This is probably 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 that it does not recognize the "new" (by which I mean 10 years) module build and install mechanism Build.PL
. CPAN wrote its own installer instead and tried to install it anyway. This will work for many Perl modules, but it probably missed some of the niceties required by DateTime.
Update the CPAN client, you can do this with the CPAN client, then try again.
source to share
Sorry for the necromancy of the thread.
I had / had 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 full bunch of more detail using Devel :: Peek Dump () s.
Suffice it to say that m / ^ \ d + $ / regex took the pPOK flag (the same as POKp?), And $ _ [0] became undef in both string and numeric contexts. I am guessing it is a bug in this particular version of perl as I cannot reproduce it on other OSes.
As a result, I changed DateTime.pm to avoid the problem as updating perl is not 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: The Devel :: Peek stuff was found 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.
source to share
Using a copy of a variable working 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 => {
source to share