Tuesday, July 28, 2009

Template Toolkit Tip for the Week

For the love of god, why did it take me 3 months to find a command to chomp white space? You're sick unto death of having to view the source of your html after a template has produced it and it's full of blank lines? Follow the link. All you need to do is add a "-" to your template toolkit markup.

[% some command here %]


[% some command here -%]

I suppose the overarching meta point here? Read documentation even when you don't think you need it directly for the task at hand. You'll find all sorts of goodies in there.

Thursday, July 16, 2009

Catalyst and DBIX::Class tip

I hadn't been using DBIX::Class with Catalyst very long before I realized that stuffing an array of Row objects into a session was a Bad Idea. a. You probably don't need all that schema and database state info that comes with it just to load your data into your html. b. you probably don't really want to try to stuff a live connection to a database into your session object and c. the things take up a boat load of session memory.

Although the DBIX::Class docs are actually pretty good it took me a while to come up with the answer:

DBIx::Class::ResultClass::HashRefInflator. If all you need is your data stuffed into a hashref and you're not using prefetches, this is what you want to use to keep your results light weight.

Sample code below is simple and works like a charm:

use DBIx::Class::ResultClass::HashRefInflator;

my $rs = $schema->resultset('CD');
while (my $hashref = $rs->next) {

Sunday, July 5, 2009

Open mouth insert foot.

So I was at YAPC:NA, which for people new to perl, is probably both the cheapest and highest quality perl conference in North America and you should totally go. And I was sitting at lunch with, among other people, Richard Dice the President of The Perl Foundation. We talked about all sorts of things. Kids daycare in Canada versus the US. Finding time to volunteer in the perl community. You know, lunch and new acquaintance blather. When it came to which talk we were going to next, I found myself uttering the words "Nah... I'm not going to [some talk]. It's about perl6 which is sort of irrelevant."

The table got quiet. Not crickets and staring at me quiet, but definitely "Yea. You're not actually as smart as I thought you were" quiet. Because saying perl6 is irrelevant to the President of The Perl Foundation.... well. It's sorta like telling a mother her baby is ugly. Both pointless and rude.

So herewith, I take it back. Your baby's not ugly. I'm just way more enamored of ways of making perl5 take on some of the utility and cleanness of perl6 than I am of getting to use perl6 since I can't actually use it yet. To mix metaphors, I hate admiring candy I don't get to eat yet. And oddly though I like other people's children, I'm not fond of their baby pictures much either.