Changeset 2283 for trunk


Ignore:
Timestamp:
09/03/19 19:40:51 (5 years ago)
Author:
nanardon
Message:

Allow to callback to SynchAccess? to follow process

File:
1 edited

Legend:

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

    r2175 r2283  
    3636} 
    3737 
    38 =head2 new( \@bases ) 
     38=head2 new( \@bases, %config ) 
    3939 
    4040Create a new SynchAccess instance over given bases 
     41 
     42C<%config>: 
     43 
     44=over 4 
     45 
     46=item cb 
     47 
     48Callback, see L<SetCB> 
     49 
     50=back 
    4151 
    4252=cut 
    4353 
    4454sub new { 
    45     my ($class, $bases) = @_; 
     55    my ($class, $bases, %config) = @_; 
    4656    bless { 
    4757        bases => [ @{ $bases } ], 
     58        %config 
    4859    }, $class; 
    4960} 
     
    6071} 
    6172 
     73=head2 SetCB ( $callback ) 
     74 
     75Set a callback to receive the object being call, return the previous one. 
     76 
     77=cut 
     78 
     79sub SetCB { 
     80    my ( $self, $cb ) = @_; 
     81 
     82    my $oldCB = $self->{cb}; 
     83    $self->{cb} = $cb; 
     84    return $oldCB; 
     85} 
     86 
    6287sub _return_all { 
    6388    my ($self, $sub, @args) = @_; 
    64     map { $_->$sub(@args) } $self->bases 
     89    my @allres; 
     90    foreach my $ba ($self->bases) { 
     91        my @res = $_->$sub(@args); 
     92        $self->{cb}->($ba, @res) if($self->{cb}); 
     93        push(@allres, @res); 
     94    } 
     95    @allres; 
    6596} 
    6697 
     
    82113    my $failure = 0; 
    83114    foreach ($self->bases) { 
    84         $_->$sub(@args) or do { 
     115        my $res = $_->$sub(@args); 
     116        $self->{cb}->($_, $res) if($self->{cb}); 
     117        $res or do { 
    85118                    la_log(LA_ERR, "SyncA: Erreur call $sub() for %s", $_); 
    86119                $failure = 1; 
     
    94127    my $failure = 0; 
    95128    foreach ($self->bases) { 
    96         $_->$sub(@args) and $failure = 1; 
     129        my $res = $_->$sub(@args) and $failure = 1; 
     130        $self->{cb}->($_, $res) if($self->{cb}); 
    97131    } 
    98132    $failure ? 0 : 1; 
     
    107141    foreach ($self->bases) { 
    108142        if ($_->is_supported_object($otype)) { 
    109             $_->rename_object($otype, $uid, $newuid) or do { 
     143            my $res = $_->rename_object($otype, $uid, $newuid); 
     144            $self->{cb}->($_, $res) if($self->{cb}); 
     145            $res or do { 
    110146                la_log(LA_ERR, 
    111147                    "Cannot get object $otype/$uid in %s/%s", 
Note: See TracChangeset for help on using the changeset viewer.