Thedi Gerber | 2 Mar 09:54
Picon

Caching of method call results.

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'" >
(Continue reading)


Gmane