I've got an object type that uses a tied array as the underlying data type. For my purposes this lets me use it as an array for certain behaviors and still call methods on it like an object. This works great in perl, but Template Toolkit refuses to let me treat it as an array in my templates. The patch below lets me do that, though.
Any chances anyone else wants to see this as well? It seems sensible to me that if the template author hands Stash a numeric index as an argument, they know they're working with some form of array. Note to others, you'll have to include an as_list() subroutine in your class for this little snippet in Template::Iterator to be happy:


   elsif (UNIVERSAL::can($data, 'as_list')) {
       $data = $data->as_list();
   }

here's the patch:

--- Stash.orig.pm       Fri Dec  5 17:06:17 2003
+++ Stash.pm    Fri Dec  5 16:54:19 2003
@@ -572,7 +572,7 @@
           return [EMAIL PROTECTED]@$item}];                       ## RETURN
       }
    }
-    elsif ($rootref eq 'ARRAY' ) {
+    elsif ($rootref eq 'ARRAY' || $item =~ /^-?\d+$/ ) {

       # if root is an ARRAY then we check for a LIST_OPS pseudo-method
       # (except for l-values for which it doesn't make any sense)


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

Reply via email to