A small patch to Text::Template.pm that tells you exactly where template warnings/errors are coming from.
If you use the Text::Template module regularly, you know that correlating a a warning/error to its location in your template code can be quite a daunting task. This is, of course, because eval'd warnings and errors calculate line numbers based from the origin of the eval'd block, rather than from the beginning of the template. I added a feature that permits Text::Template to spew such messages with their actual line number info intact, as well as their originating template file name (if applicable). This has made debugging complex templates much faster for me. To use the feature, set the parameter LINENUMS => 1 in your calls to Text::Template->new().

To apply this patch to your Template.pm file, save the patch text below to a file and run patch Template.pm patchfile.

56a57 > my $linenums = _param('linenums', %a); 68c69,70 < (defined $alt_delim ? (DELIM => $alt_delim) : ()), --- > (defined $linenums ? (LINENUMS => $linenums) : ()), > (defined $alt_delim ? (DELIM => $alt_delim) : ()), 85a88 > $self->{FILENAME} = $self->{SOURCE}; 261a265 > my $fi_filename = $fi_self->{FILENAME} || 'text_template'; 272c276,277 < my $fi_progtext = "package $fi_eval_package; $fi_prepend;\n#li +ne 1\n$fi_text" --- > my $fi_lncomment = ($fi_self->{LINENUMS} ? "#line $fi_lineno $ +fi_filename" : "#line 1"); > my $fi_progtext = "package $fi_eval_package; $fi_prepend;\n$fi +_lncomment\n$fi_text"

In reply to Text::Template debugging made easier by MeowChow

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.