package LATMOS::Accounts::SynchAccess::base; use strict; use warnings; use vars qw($AUTOLOAD); use Carp; use LATMOS::Accounts::Log; our $VERSION = (q$Rev$ =~ /^Rev: (\d+) /)[0]; =head1 NAME LATMOS::Accounts::SynchAccess::base - Fake base object for sync access =head1 DESCRIPTION This module fake a base object to send same actions tu multiple base. This is used for actions basic synchronisation process cannot handle. This module contain common functions between Base and Object managment. =head1 FUNCTIONS =cut sub AUTOLOAD { my ($self, @args) = @_; my ($constname, $sub) = $AUTOLOAD =~ m/(.*)::([^:]+)/; if ($sub =~ /^(wexported)/) { $self->_no_trap($sub, @args); } elsif ($sub =~ /^(check_password)$/) { $self->_run_first($sub, @args); } else { $self->_trap_false($sub, @args); } } =head2 new( \@bases ) Create a new SynchAccess instance over given bases =cut sub new { my ($class, $bases) = @_; bless { bases => [ @{ $bases } ], }, $class; } =head2 bases Return lists of bases in ths instance. =cut sub bases { my ($self) = @_; @{ $self->{bases} || []} } sub _return_all { my ($self, $sub, @args) = @_; map { $_->$sub(@args) } $self->bases } sub _run_first { my ($self, $sub, @args) = @_; my ($fbase) = $self->bases; $fbase->$sub(@args); } sub _no_trap { my ($self, $sub, @args) = @_; foreach ($self->bases) { $_->$sub(@args); } } sub _trap_false { my ($self, $sub, @args) = @_; my $failure = 0; foreach ($self->bases) { $_->$sub(@args) or do { la_log(LA_ERR, "SyncA: Erreur call $sub() for %s", $_); $failure = 1; }; } $failure ? 0 : 1; } sub _trap_true { my ($self, $sub, @args) = @_; my $failure = 0; foreach ($self->bases) { $_->$sub(@args) and $failure = 1; } $failure ? 0 : 1; } =head2 rename_object =cut sub rename_object { my ($self, $otype, $uid, $newuid) = @_; foreach ($self->bases) { if ($_->is_supported_object($otype)) { $_->rename_object($otype, $uid, $newuid) or do { la_log(LA_ERR, "Cannot get object $otype/$uid in %s/%s", $_->type, $_->label ); return; }; } } return 1; } sub DESTROY {} 1; __END__ =head1 SEE ALSO L, L =head1 AUTHOR Olivier Thauvin, Eolivier.thauvin@latmos.ipsl.frE =head1 COPYRIGHT AND LICENSE Copyright (C) 2012 CNRS SA/CETP/LATMOS This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself, either Perl version 5.10.0 or, at your option, any later version of Perl 5 you may have available. =cut