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

Last change on this file since 1262 was 1262, checked in by nanardon, 10 years ago

fix sync/rename_object()

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