package SL::Template::Plugin::HTMLFixes;
 
 use Template::Plugin::HTML;
+use Template::Stash;
 
 1;
 
 }
 
 1;
+
+package Template::Stash;
+
+# A method for forcing list context. If a method uses 'wantarray' then
+# calling that method from Template will do strange stuff like chosing
+# scalar context. The most obvious offender are RDBO relationships.
+
+# Example of how NOT to test whether or not a customer has contacts:
+#   [% IF customer.contacts.size %] ...
+# Instead force list context and then test the size:
+#   [% IF customer.contacts.as_list.size %] ...
+$Template::Stash::LIST_OPS->{ as_list } = sub {
+  return ref( $_[0] ) eq 'ARRAY' ? shift : [shift];
+};
+
+1;