perl-embperl mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Terrence Brannon <metap...@urth.org>
Subject [PATCH] DBIx::Recordset::PreFetchIfExpires()
Date Thu, 23 Oct 2003 16:13:55 GMT
The original code for this routine had a logic error:

sub PreFetchIfExpires
   
    {
    my ($self, $rs) = @_ ;
   
    return if (!defined ($self -> {'*ExpiresTime'}) && $self -> 
{'*ExpiresTime'} < time) ;
    return if (ref ($self -> {'*Expires'}) ne 'CODE' || ! (&{$self -> 
{'*Expires'}}($self))) ;
   
    $self -> PreFetch ($rs) ;
    }

Now, just imagine that you have set !Expires to a number and after a 
period of time
ExpiresTime > 10.
So, the first "return if ..." fails and the subroutine continues, but 
because you did not use a code reference for !Expires (remember the 
above sentence: you set it to a number), the second return if is 
triggered and the subroutine returns without re-prefetching.

--- Recordset.pm~    2001-07-09 20:58:58.000000000 -0700
+++ Recordset.pm    2003-10-23 08:58:53.390625000 -0700
@@ -3360,10 +3360,14 @@
     {
     my ($self, $rs) = @_ ;
    
-    return if (!defined ($self -> {'*ExpiresTime'}) && $self -> 
{'*ExpiresTime'} < time) ;
-    return if (ref ($self -> {'*Expires'}) ne 'CODE' || ! (&{$self -> 
{'*Expires'}}($self))) ;
+    my $prefetch;
+    if (ref ($self -> {'*Expires'}) eq 'CODE') {
+      $prefetch =  $self -> {'*Expires'}->($self);
+    } elsif (defined ($self -> {'*ExpiresTime'})) {
+      $prefetch =  $self -> {'*ExpiresTime'} < time
+    }
    
-    $self -> PreFetch ($rs) ;
+    $self -> PreFetch ($rs) if $prefetch;
     }
 
 ## 
----------------------------------------------------------------------------
  



---------------------------------------------------------------------
To unsubscribe, e-mail: embperl-unsubscribe@perl.apache.org
For additional commands, e-mail: embperl-help@perl.apache.org


Mime
View raw message