Thanks to everyone for their comments.  I've decided that it would
indeed be wrong to change the hash.list method without warning, no 
matter how broken it is or how much better it could be.

So the existing behaviour has gone back in, but the method has been
documented as likely to change in TT3 and warning people to use the 
alternative instead.

I've created a new hash.pairs method to go with hash.keys and hash.values.
This returns what the current hash.list does (a list of hashes containing
{ key => $k, value => $v }).  So the docs tell people to stop using 
hash.list and use hash.pairs instead.

I've also created a new hash.items method which does what hash.each 
currently does in simply expanding the hash into a list: [ %$hash ].  
People using hash.each should change this to hash.items at some point
because in TT3, hash.each will change to return what each does in Perl, 
i.e. the same thing as hash.pairs.  

For TT3 we'll continue to provide hash.pairs for those who start using 
it now, but by then hash.each will do the same thing and be the recommended
method.  

So hopefully that gives everyone a clear upgrade path and plenty of
warning that things are going to change.

    TT2 Old    | TT2 New         | TT3
    -----------|-----------------|----------------
    hash.list  | hash.pairs      | hash.each
               | (or hash.list)  | (or hash.pairs)
    hash.each  | hash.items      | hash.items
               | (or hash.each)  |

As for the list.hash method, this has never been documented so I'm not
worried about changing it.  By default this now returns a hash array
composed from the list items, e.g. { @$list }.  If you provide a 
numerical argument, it implements the old (but undocumented) behaviour
of creating a hash that looks like an array with numerical keys, starting
at the number provided.

   list = [ foo, bar, baz, wiz ]
   list.hash     # { foo => bar, baz => wiz }
   list.hash(0)  # { 0 => foo, 1 => bar, 2 => baz, 3 => wiz }
   list.hash(1)  # { 1 => foo, 2 => bar, 3 => baz, 4 => wiz }

So if anyone is currently using this then they just have to change
list.hash to list.hash(0) to get the same effect.

Cheers
A


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

Reply via email to