> In a good OO system with objects > representing the > data model, I found it exhausting to use H::T when I could > just to this > in TT: > > [% user.name %] > > > Am I just being stupid, or are there better ways of doing > these things > in H::T?
I'm a little late to the dance but I generally unplug over the weekend. We use H::T here and I too got annoyed with the need to flatten all of my objects. However, with so much invested in H::T by that time, we just wrote a toHash() method which is inherited by all of our objects. It predictably takes the object attributes and churns out a hash (and is smart enough to do a recursive descent if need be). It also take an optional "prefix" so that you could pass in a prefix of "user." and then be able to <tmpl_var user.name> if you wanted. It was an easy way to reduce the pain of H::T and yet not reinvent the wheel. A simple $tmpl->param($myObj->toHash(prefix => 'user.')) works fairly well in most cases. I'm sure there's a better/more robust way to do it (yeah, switch to TT ;-) but we found that this was sufficient to reduce the annoyance factor enough to allow us to get on with it. Also, we use HTML::Template::Expr to cheat liberally where appropriate. :-) Separation of HTML and logic is a good thing, but like most good things, there are exceptions. Since our controllers were starting to get really cluttered with a lot of "if this simple thing is true then pass this boolean to the template since the template itself can't ask whether this simple thing is true" code, which HTML::Template::Expr helps ease. Hope that helps. I really like H::T for it's simplicity and ease of understanding and picking up for new folks, and didn't want to toss that away unless I had to. -Fran