I am most likely looking in the wrong places and have missed some crucial piece of information. I can't get DateTime objects to play well with Template::Stash - the Template::Stash seems to want to compare the DateTime object against the template root, but the DateTime object does not want to be compared with anything other than a DateTime object, or something sufficiently similar. See my code below - it is some convoluted way of printing todays date, except it doesn't:

use strict; use DateTime; use Template; my $config = {}; my $template = Template->new($config); my $input = \'[% calendar.ymd(".") %]'; # process input template, substituting variables $template->process($input, { calendar => DateTime->now }) or die $template->error();

After patching DateTime.pm so it gives some better error diagnostics, I get

undef error - Cannot compare a datetime to a regular scalar (2005-02-2 +8T21:51:58 / Template::Stash=HASH(0x2048a14)) at c:/perl/site/5.8.5/l +ib/Template/Stash.pm line 582

but I don't want to believe that nobody has used Template::Toolkit and DateTime together, so the error must be somewhere in my usage of one of the two.

Update: DateTime v0.28, Template::Toolkit 2.14

Update 2: I hacked myself a workaround by removing the overloaded string comparison of DateTime. This is horribly ugly and there must be a better way :-(


In reply to Using DateTime together with Template::Toolkit by Corion

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.