the most common template toolkit mistake

7
The Most Common Template Toolkit Mistake Perrin Harkins We Also Walk Dogs

Upload: perrin-harkins

Post on 13-Jun-2015

872 views

Category:

Technology


0 download

DESCRIPTION

This was a lightning talk presented at YAPC::NA 2011.

TRANSCRIPT

Page 1: The Most Common Template Toolkit Mistake

The Most Common Template Toolkit Mistake

Perrin HarkinsWe Also Walk Dogs

Page 2: The Most Common Template Toolkit Mistake

Yesterday, Uri did a lighting talk

Template::Simple has a benchmark scriptApparently it is faster and lighter than Template Toolkit

Page 3: The Most Common Template Toolkit Mistake

Years ago, I did a talk on templating systemshttp://tmpl.notlong.comSince then, many people have told me about their new module

Page 4: The Most Common Template Toolkit Mistake

People often break Template Toolkit's cachemy $tt = Template->new({ INCLUDE_PATH => '/usr/local/templates'}) || die "$Template::ERROR\n";

$tt>process( 'letters/overdrawn', $vars) || die $tt->error(), "\n";

Don't throw away your Template instance!The cache is in there!

Page 5: The Most Common Template Toolkit Mistake

Uri's benchmark didn't do that

It did something else: template in a scalar refIs that a bug?

How can you fix it?

Subclass Template::Provider, e.g. Template::Provider::MD5

Temp file

Page 6: The Most Common Template Toolkit Mistake

Template::Simple is still much faster

But Template Toolkit isn't as slow as it looked.

More than 300% faster than before.

Page 7: The Most Common Template Toolkit Mistake

Why I like slow and heavy templates

Separates presentation code from model and controller● Keeps display things that wouldn't make sense in a cron

job in your output layer● Format dates and numbers● Put things in multiple columns●Display objects●Maybe sort things?

Mason, etc. are fine for this, not just TT