Guys,
Okay, I've been using TT2 for a while now, and I'm really starting to get into it. It's quite a lot better than any other templating tool I've used. I even got the badger book. :-)
Now I have a design question. I have an object, which acts (FTMP) like a Perl pseudohash. Specifically, you can use it like a hashref, or like an arrayref. I use it for storing rows I get back from the database. Consequently, I have lots of arrays of these lying around, which I naturally want to get into templates.
My first attempt was just to toss an array into the $vars I send to TT2. This didn't work, of course, because even though you can _use_ it like a hashref, it _isn't_ a hashref. It's an object. So TT2 wanted to use my column names as methods. After some thought, I decided to solve this by using AUTOLOAD to make any method that matched a column name return the data. It's an imperfect solution, but it works.
The next problem I ran into was of the same sort. I keep thinking of these things (the name of the object is "DataRow", BTW) as a hashref, even though I know better ... so I inevitably tried to use the "keys" virtual method on one. Didn't work, because DataRow doesn't have a keys() method. So I made one.
So, now things are working pretty much okay, but I'm worried that I've started down a dangerous path. I'm thinking that I'm going to end up implementing all of the virtual functions of hashes (and maybe even arrays) that TT2 already has built-in all over again. Reinventing not just one wheel here ...
So I'm wondering if anyone else has another possible solution. Is there another direction I should try that I haven't thought of yet? Or is my present course really the best way?
TIA for any thoughts and help.
-- Buddy
_______________________________________________ templates mailing list [EMAIL PROTECTED] http://lists.template-toolkit.org/mailman/listinfo/templates
