Caching of method call results.
Thedi Gerber <[email protected]> Mon, 02 Mar 2009 09:54:42 +0100
| Newsgroups | gmane.comp.lang.perl.modules.petal |
|---|---|
| Message-ID | <[email protected]> |
Hello,
I wrote a method which returns alternating 'even' and 'odd' for table rows:
sub row_class {
my $self = shift;
$self->{ row_class } = ! $self->{ row_class };
return $self->{ row_class } ? 'even' : 'odd';
}
Actually the details are much more complicated, but the problem can be described with this example.
In a template I call this method
<tr class="odd"
tal:attributes="class utils/row_class" >
...
<tr class="odd"
tal:attributes="class utils/row_class" >
It seems that Petal caches method call results, hence I always get the same result from method
row_class.
As a work around I tried to pass a dummy argument:
<tr class="odd"
tal:attributes="class utils/row_class '1'" >
...
<tr class="odd"
tal:attributes="class utils/row_class '2'" >
This works as desired, but is rather ugly.
Is there a better way?
Regards
Thedi [email protected]