source: LATMOS-Accounts/lib/LATMOS/Accounts/Bases.pm @ 5

Last change on this file since 5 was 5, checked in by nanardon, 15 years ago
  • add Unix base access
  • Property svn:keywords set to Id Rev
File size: 2.5 KB
Line 
1package LATMOS::Accounts::Bases;
2
3use 5.010000;
4use strict;
5use warnings;
6use LATMOS::Accounts::Bases::Objects;
7
8our $VERSION = (q$Rev$ =~ /^Rev: (\d+) /)[0];
9
10=head1 NAME
11
12LATMOS::Accounts::Bases - Base class for account data bases
13
14=head1 SYNOPSIS
15
16  use LATMOS::Accounts::Bases;
17  my $base = LATMOS::Accounts::Bases->new('type', %options);
18  ...
19
20=head1 DESCRIPTION
21
22This module provide basic functions for various account base
23
24=head1 FUNTIONS
25
26=cut
27
28=head2 new($type, %options)
29
30Return, if success, a new data base account object, $type is
31account base type, %options to setup the base.
32
33=cut
34
35sub new {
36    my ($class, $type, %options) = @_;
37
38    my $pclass = ucfirst(lc($type));
39    eval "require LATMOS::Accounts::Bases::$pclass;";
40    if ($@) { return } # error message ?
41    return "LATMOS::Accounts::Bases::$pclass"->new(%options);
42}
43
44=head2 get_object($type, $id)
45
46Return an object of $type (typically user or group) having identifier
47$id.
48
49=cut
50
51sub get_object {
52    my ($self, $otype, $id) = @_;
53
54    return LATMOS::Accounts::Bases::Objects->new($self, $otype, $id);
55}
56
57=head2 load
58
59Make account base loading data into memory if need.
60Should always be called, if database fetch data on the fly
61(SQL, LDAP), the function just return True.
62
63=cut
64
65sub load { 1 }
66
67=head2 is_transactionnal
68
69Return True is the database support commit and rollback
70
71=cut
72
73sub is_transactionnal {
74    my ($self) = @_;
75    return($self->can('_rollback') && $self->can('_commit'));
76}
77
78=head2 commit
79
80Save change into the database if change are not done immediately.
81This should always be called as you don't know when change are applied.
82
83Return always true if database does not support any transaction.
84
85The driver should provides a _commit functions to save data.
86
87=cut
88
89sub commit {
90    my ($self) = @_;
91    return $self->can('_commit') ? $self->_commit : 1;
92}
93
94=head2 rollback
95
96If database support transaction, rollback changes. Return false
97if database does not support.
98
99If supported, driver should provides a _rollback functions
100
101=cut
102
103sub rollback {
104    my ($self) = @_;
105    return $self->can('_rollback') ? $self->_commit : 0;
106}
107
1081;
109
110__END__
111
112=head1 SEE ALSO
113
114=head1 AUTHOR
115
116Thauvin Olivier, E<lt>olivier.thauvin.ipsl.fr.thauvin@latmos.ipsl.fr<gt>
117
118=head1 COPYRIGHT AND LICENSE
119
120Copyright (C) 2009 by Thauvin Olivier
121
122This library is free software; you can redistribute it and/or modify
123it under the same terms as Perl itself, either Perl version 5.10.0 or,
124at your option, any later version of Perl 5 you may have available.
125
126=cut
Note: See TracBrowser for help on using the repository browser.