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: 26085
Status: resolved
Priority: 0/
Queue: DateTime

People
Owner: Nobody in particular
Requestors: chris+rt [...] chrisdolan.net
Cc:
AdminCc:

Bug Information
Severity: Normal
Broken in: 0.37
Fixed in: 0.38



Subject: Bad interaction with Template-Toolkit
The minimal testcase below demonstrates a failure when a DateTime instance method is used inside of a Template-Toolkit document. The problem is that Template::Stash does an 'eq' comparison of it's stash hash against every dotted operand. Due to overload, this invokes DateTime::_compare, which croaks. I'm not sure whose fault this is because I upgraded my Template-Toolkit from v2.15 to v2.18 on the same day that I upgraded DateTime... However, it seems to me that DateTime is being excessively strict. My opinion is that _compare should return false instead of croaking if one object is not a DateTime instance. Chris #!/usr/bin/perl -w use strict; use DateTime 0.37; use Template 2.18; Template->new->process(\*DATA, {dt => DateTime->now}) || die Template->error; __DATA__ [% dt.year %]
A very-closely related bug in RT for Template-Toolkit: http://rt.cpan.org/Ticket/Display.html?id=21910 The workaround I'm employing in my own code is: use DateTime; BEGIN { package DateTime; no overload 'cmp'; } Chris
Subject: Re: [rt.cpan.org #26085] Bad interaction with Template-Toolkit
Date: Wed, 4 Apr 2007 08:53:30 -0500 (CDT)
To: via RT <bug-DateTime [...] rt.cpan.org>
From: Dave Rolsky <autarch [...] urth.org>
On Wed, 4 Apr 2007, via RT wrote: Show quoted text
> I'm not sure whose fault this is because I upgraded my Template-Toolkit > from v2.15 to v2.18 on the same day that I upgraded DateTime...
Looking at RT 21910, this relaly seems like a bug in TT. -dave /*=================================================== VegGuide.Org www.BookIRead.com Your guide to all that's veg. My book blog ===================================================*/
Subject: Re: [rt.cpan.org #26085] Bad interaction with Template-Toolkit
Date: Wed, 4 Apr 2007 20:01:44 -0500
To: bug-DateTime [...] rt.cpan.org
From: Chris Dolan <chris [...] chrisdolan.net>
On Apr 4, 2007, at 8:53 AM, autarch@urth.org via RT wrote: Show quoted text
> <URL: http://rt.cpan.org/Ticket/Display.html?id=26085 > > > On Wed, 4 Apr 2007, via RT wrote: >
>> I'm not sure whose fault this is because I upgraded my Template- >> Toolkit >> from v2.15 to v2.18 on the same day that I upgraded DateTime...
> > Looking at RT 21910, this relaly seems like a bug in TT.
There is indeed a bug in TT. However, I think DateTime is behaving inappropriately and mysteriously and bears most of the blame. After all, who can really fault TT for simply using eq? Certainly the TT author could not have anticipated a croak() when using eq. The problem is that DateTime is falling back to cmp to implement overloaded eq. Instead, DateTime needs an eq implementation that always returns a boolean. This could be accomplished by changing the _compare implementation, but a better solution is to add new overloads for eq and ne. Perhaps this: use overload ( 'fallback' => 1, '<=>' => '_compare_overload', 'cmp' => '_compare_overload', '""' => '_stringify', '-' => '_subtract_overload', '+' => '_add_overload', 'eq' => '_equivalent', # added 'ne' => '_not_equivalent', # added ); ... sub _equivalent { my ( $class, $dt1, $dt2 ) = ref $_[0] ? ( undef, @_ ) : @_; return unless ( DateTime::Helpers::can( $dt1, 'utc_rd_values' ) && DateTime::Helpers::can( $dt2, 'utc_rd_values' ) ); return !$class->compare($dt1, $dt2); } sub _not_equivalent { return !_equivalent(@_); } Chris