[Catalyst] TT macro to avoid excessive $c->uri_for calls

Tobias Kremer list at funkreich.de
Tue Aug 7 08:43:30 GMT 2007


I'm wondering if it has any bad side effects to have a TT macro which is set to
$c->uri_for. If I'm remembering previous posts on this topic correctly, calling
uri_for() repeatedly has quite a big impact on performance which really matters
most for my current application. I have this in a global macros.tt2 file:

[%
    base = Catalyst.req.base;
    static = Catalyst.config.hosts.static;
    images = Catalyst.config.hosts.images;
    site.url = {
        base    = base
        static  = static
        images  = images
    }
-%]

That way I can easily change the location of my static files and images to
another server or place using the Catalyst config file and generate links like
this:

<img src="[% site.url.images %]logo.png" />
<a href="[% site.url.base %]user/whatever">bla</a>

etc.

Any comments? Thanks!

--Tobias



More information about the Catalyst mailing list