Thank you. That is much neater, but it's not quite the same thing: It tests that the template exists *and works*. Which would be useful in a public-facing system, but a bit of a drawback in development, where it would obscure (and worse, silence) an error of any kind that happened behind the TRY statement.

I'd also be mildly concerned about using an error mechanism to handle an expected event: apart from the minor misapplication, I would guess that it's a lot more economical to call -e -f a few times than to go through the whole Template exception-handling mechanism and then discard its output. A minor difference, probably, but if the try and catch was in a list-display loop I could easily be causing and intercepting twenty or fifty deaths per page...

So I guess I am going to have to stumble around inside the template parser and attempt to extend its syntax. I'm sure it will be very good for me.

update Actually, maybe all that's needed is a configuration option that if set, causes the compiler to return false rather than raising an exception when a template file can't be found. It should be easier than going into the parser, anyway. Shudder.


In reply to Re: •Re: testing for the existence of a tt template: better way? by thpfft
in thread testing for the existence of a tt template: better way? by thpfft

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.