Ignore:
Timestamp:
10/01/12 18:14:22 (12 years ago)
Author:
nanardon
Message:

add temp_switch_unexported() function

Location:
trunk/LATMOS-Accounts/lib/LATMOS/Accounts
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/LATMOS-Accounts/lib/LATMOS/Accounts/Bases.pm

    r1113 r1182  
    7979    } 
    8080    return($old || 0); 
     81} 
     82 
     83=head2 temp_switch_unexported($CODE, $value) 
     84 
     85Switch the base to unexported mode given by C<$value>, run C<$CODE>, restore 
     86back the previous state and return the result of code ref. 
     87 
     88=cut 
     89 
     90sub temp_switch_unexported (&;$) { 
     91    my ($self, $sub, $value) = @_; 
     92 
     93    my $old = $self->unexported($value || 0); 
     94    my $res = $sub->(); 
     95    $self->unexported($old); 
     96    return $res; 
    8197} 
    8298 
  • trunk/LATMOS-Accounts/lib/LATMOS/Accounts/Bases/Objects.pm

    r1181 r1182  
    534534        $field, $min, $max); 
    535535    my %existsid; 
    536     my $oldunexported = $base->unexported(1); 
    537     foreach ($base->list_objects($class->type)) { 
    538         my $obj = $base->get_object($class->type, $_) or next; 
    539         my $id = $obj->_get_c_field($field) or next; 
    540         $existsid{$id + 0} = 1; 
    541     } 
    542     $base->unexported($oldunexported); 
     536    $base->temp_switch_unexported(sub { 
     537        foreach ($base->list_objects($class->type)) { 
     538            my $obj = $base->get_object($class->type, $_) or next; 
     539            my $id = $obj->_get_c_field($field) or next; 
     540            $existsid{$id + 0} = 1; 
     541        } 
     542    }, 1); 
    543543    $min += 0; 
    544544    $max += 0; 
Note: See TracChangeset for help on using the changeset viewer.