Skip Menu |

Preferred bug tracker

Please visit the preferred bug tracker to report your issue.

This queue is for tickets about the DateTime CPAN distribution.

Report information
The Basics
Id: 94659
Status: rejected
Priority: 0/
Queue: DateTime

People
Owner: Nobody in particular
Requestors: drieux [...] yahoo-inc.com
Cc:
AdminCc:

Bug Information
Severity: (no value)
Broken in: (no value)
Fixed in: (no value)



Subject: Reference found where even-sized list expected at DateTime-1.08/lib/DateTime.pm line 1673
Date: Fri, 11 Apr 2014 22:40:12 +0000
To: "bug-DateTime [...] rt.cpan.org" <bug-DateTime [...] rt.cpan.org>
From: Drieux Hampe <drieux [...] yahoo-inc.com>
the addition to the 25add-subtract.t will show the bug. *** t/25add-subtract.t.ORIG Fri Apr 11 15:10:39 2014 --- t/25add-subtract.t Fri Apr 11 15:16:21 2014 *************** *** 31,34 **** --- 31,43 ---- is( $dt2->second, 59, 'second is 59' ); } + # the subtract bug + { + my $hours = 1; + my $dts = DateTime->now(); + $dts->subtract( DateTime::Duration->new( hours => $hours ) ); + # which will generate the warning: + # Reference found where even-sized list expected at /Users/drieux/tmp/UnWarp/DateTime-1.08/lib/DateTime.pm line 1673. + # $DateTime::VERSION = '1.08'; + } done_testing(); There are two solutions, a. modulo of the @_ b. test $_[0] to see if it is a ref so that my $dur = $dt2->subtract_datetime($dt1); will work with all of the hash argument passing Solution A: *** lib/DateTime.pm.ORIG Fri Apr 11 15:16:42 2014 --- lib/DateTime.pm Fri Apr 11 15:22:51 2014 *************** *** 1670,1676 **** sub subtract { my $self = shift; ! my %p = @_; my %eom; $eom{end_of_month} = delete $p{end_of_month} --- 1670,1676 ---- sub subtract { my $self = shift; ! my %p = (@_ % 2)? () :@_; my %eom; $eom{end_of_month} = delete $p{end_of_month} Solution B: *** lib/DateTime.pm.ORIG Fri Apr 11 15:16:42 2014 --- lib/DateTime.pm Fri Apr 11 15:29:50 2014 *************** *** 1670,1677 **** sub subtract { my $self = shift; ! my %p = @_; ! my %eom; $eom{end_of_month} = delete $p{end_of_month} if exists $p{end_of_month}; --- 1670,1680 ---- sub subtract { my $self = shift; ! my %p; ! unless ( ref($_[0]) ) { ! %p = @_; ! } ! my %eom; $eom{end_of_month} = delete $p{end_of_month} if exists $p{end_of_month}; --drieux
This is why there are ->subtract and ->subtract_duration methods. The latter takes an object.