source: trunk/LATMOS-Accounts/lib/LATMOS/Accounts/SynchAccess/base.pm @ 2255

Last change on this file since 2255 was 2175, checked in by nanardon, 5 years ago

Always create internal at db load

  • Property svn:keywords set to Id Rev
File size: 2.8 KB
Line 
1package LATMOS::Accounts::SynchAccess::base;
2
3use strict;
4use warnings;
5use vars qw($AUTOLOAD);
6use Carp;
7use LATMOS::Accounts::Log;
8
9our $VERSION = (q$Rev: 1405 $ =~ /^Rev: (\d+) /)[0];
10
11=head1 NAME
12
13LATMOS::Accounts::SynchAccess::base - Fake base object for sync access
14
15=head1 DESCRIPTION
16
17This module fake a base object to send same actions tu multiple base. This is
18used for actions basic synchronisation process cannot handle.
19
20This module contain common functions between Base and Object managment.
21
22=head1 FUNCTIONS
23
24=cut
25
26sub AUTOLOAD {
27    my ($self, @args) = @_;
28    my ($constname, $sub) = $AUTOLOAD =~ m/(.*)::([^:]+)/;
29    if ($sub =~ /^(wexported)/) {
30        $self->_no_trap($sub, @args);
31    } elsif ($sub =~ /^(check_password)$/) {
32        $self->_run_first($sub, @args);
33    } else {
34        $self->_trap_false($sub, @args);
35    }
36}
37
38=head2 new( \@bases )
39
40Create a new SynchAccess instance over given bases
41
42=cut
43
44sub new {
45    my ($class, $bases) = @_;
46    bless {
47        bases => [ @{ $bases } ],
48    }, $class;
49}
50
51=head2 bases
52
53Return lists of bases in ths instance.
54
55=cut
56
57sub bases {
58    my ($self) = @_;
59    @{ $self->{bases} || []}
60}
61
62sub _return_all {
63    my ($self, $sub, @args) = @_;
64    map { $_->$sub(@args) } $self->bases
65}
66
67sub _run_first {
68    my ($self, $sub, @args) = @_;
69    my ($fbase) = $self->bases;
70    $fbase->$sub(@args);
71}
72
73sub _no_trap {
74    my ($self, $sub, @args) = @_;
75    foreach ($self->bases) {
76        $_->$sub(@args);
77    }
78}
79
80sub _trap_false {
81    my ($self, $sub, @args) = @_;
82    my $failure = 0;
83    foreach ($self->bases) {
84        $_->$sub(@args) or do {
85                    la_log(LA_ERR, "SyncA: Erreur call $sub() for %s", $_);
86                $failure = 1;
87        };
88    }
89    $failure ? 0 : 1;
90}
91
92sub _trap_true {
93    my ($self, $sub, @args) = @_;
94    my $failure = 0;
95    foreach ($self->bases) {
96        $_->$sub(@args) and $failure = 1;
97    }
98    $failure ? 0 : 1;
99}
100
101=head2 rename_object
102
103=cut
104
105sub rename_object {
106    my ($self, $otype, $uid, $newuid) = @_;
107    foreach ($self->bases) {
108        if ($_->is_supported_object($otype)) {
109            $_->rename_object($otype, $uid, $newuid) or do {
110                la_log(LA_ERR,
111                    "Cannot get object $otype/$uid in %s/%s",
112                    $_->type,
113                    $_->label
114                );
115                return;
116            };
117        }
118    }
119    return 1;
120}
121
122sub DESTROY {}
123
1241;
125
126__END__
127
128=head1 SEE ALSO
129
130L<LATMOS::Accounts>, L<LATMOS::Accounts::Bases>
131
132=head1 AUTHOR
133
134Olivier Thauvin, E<lt>olivier.thauvin@latmos.ipsl.frE<gt>
135
136=head1 COPYRIGHT AND LICENSE
137
138Copyright (C) 2012 CNRS SA/CETP/LATMOS
139
140This library is free software; you can redistribute it and/or modify
141it under the same terms as Perl itself, either Perl version 5.10.0 or,
142at your option, any later version of Perl 5 you may have available.
143
144=cut
Note: See TracBrowser for help on using the repository browser.