Andy Wardley wrote:
I just got bitten (again) by a limitation in Template::Stash.  Stephen
Howard provided a patch to fix it and I added it, but left it commented
out pending comments from anyone (and also pending the tuits to dive
into the XS Stash to make the same fix).

http://template-toolkit.org/pipermail/templates/2003-December/005417.html

Well we don't seem to have had any comments since then, and with fresh bite marks to show for it, I'm going ahead and activating it unless I hear any blood-curdling screams to the contrary.

I'll also have a look at updating the XS Stash to do the same thing
so you may be hearing a few blood-curdling screams from me :-)

------------------------------------------------------------------
This seems ok to me. This one seems like one that will not hit too many people. 
Probably should make a note to look out for it in the release notes, though.
------------------------------------------------------------------


For some totally half-baked reason that now I can fathom not, I made the hash.list method return a stupidly complex list of hash references:

  { pi => 3.14 } => [ { key ='pi', value='3.14' } ]

and the list.hash method return an equally useless hash:

  [ 3.14, 2.718 ] => { 0 => 3.14, 1 => 2.718 }

So I'm proposing that I fix them too and make them do what they should
always have done - a straight conversion between list and hash

  hash.list => [ %$hash ]
  list.hash => { @$list }
Any objections?

------------------------------------------------------------------
This seems to make sense to me. The hash method (on lists) is probably rarely used as I don't think it's documented as a list vmethod currently.
The hash.list one is a little worrying, though. I can see someone doing the 
following:
[% hash = {a => 1, b => 2, c=> 3,} %]
[% FOREACH h IN hash.list %]
[% h.key %] [% h.value %]<br>
[% END %]

Granted that doesn't make much sense when you can do:
[% FOREACH h IN hash %]
[% h.key %] [% h.value %]<br>
[% END %]

Not only that, but if a user does:
hash.list.size();
They will not get the number of elements in the hash. (Someone might do this if 
they have multiple objects coming to that point, be it scalar, list, or hash.
For example:
obj_array = [ ['x', 'y', 'z'], {a => 3, b=> 3}, 'b'  ];
[% FOREACH obj IN obj_array %]
 [% IF (obj.list.size > 2) %]
   # do something
 [% END %]
[% END %]

Other than those two, I can't really think of any other uses, and even those 
two seem like they'd be rare. I'd say the list.hash one sounds fine, but I'm 
neutral on the hash.list() one. On one hand it probably should return a normal 
list, but on the other, it could break something. Also that functionality is 
already provided (wrongly?) via the 'each' parameter and the 'each' virtual 
method. I think it could be argued (for TT3, or if we're changing hash.list() 
then maybe now) that the 'each' parameter and virtual method should return an 
array of arrays instead. It doesn't really match the functionality of Perl. For 
example, it's like doing:
my @array = each %hash;
and expecting it to do this:
my @array = %hash;

When you use each, you expect a key and a value to be returned, not the entire 
list of the hash. So I think an array of arrays would probably be good there. 
That way you can iterate through the list and have access to each key/value 
pair.

Just my $0.02 to muddy the waters. ;)

-- Josh

_______________________________________________
templates mailing list
[email protected]
http://lists.template-toolkit.org/mailman/listinfo/templates

Reply via email to