[2] | 1 | package LATMOS::Accounts::Bases; |
---|
| 2 | |
---|
| 3 | use 5.010000; |
---|
| 4 | use strict; |
---|
| 5 | use warnings; |
---|
| 6 | use LATMOS::Accounts::Bases::Objects; |
---|
| 7 | |
---|
[3] | 8 | our $VERSION = (q$Rev$ =~ /^Rev: (\d+) /)[0]; |
---|
[2] | 9 | |
---|
[3] | 10 | =head1 NAME |
---|
| 11 | |
---|
| 12 | LATMOS::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 | |
---|
| 22 | This module provide basic functions for various account base |
---|
| 23 | |
---|
| 24 | =head1 FUNTIONS |
---|
| 25 | |
---|
| 26 | =cut |
---|
| 27 | |
---|
| 28 | =head2 new($type, %options) |
---|
| 29 | |
---|
| 30 | Return, if success, a new data base account object, $type is |
---|
| 31 | account base type, %options to setup the base. |
---|
| 32 | |
---|
| 33 | =cut |
---|
| 34 | |
---|
[2] | 35 | sub 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 | |
---|
[3] | 44 | =head2 get_object($type, $id) |
---|
| 45 | |
---|
| 46 | Return an object of $type (typically user or group) having identifier |
---|
| 47 | $id. |
---|
| 48 | |
---|
| 49 | =cut |
---|
| 50 | |
---|
[2] | 51 | sub get_object { |
---|
| 52 | my ($self, $otype, $id) = @_; |
---|
| 53 | |
---|
| 54 | return LATMOS::Accounts::Bases::Objects->new($self, $otype, $id); |
---|
| 55 | } |
---|
| 56 | |
---|
[3] | 57 | =head2 is_transactionnal |
---|
[2] | 58 | |
---|
[3] | 59 | Return True is the database support commit and rollback |
---|
[2] | 60 | |
---|
[3] | 61 | =cut |
---|
[2] | 62 | |
---|
[3] | 63 | sub is_transactionnal { |
---|
| 64 | my ($self) = @_; |
---|
| 65 | return($self->can('_rollback') && $self->can('_commit')); |
---|
| 66 | } |
---|
[2] | 67 | |
---|
[3] | 68 | =head2 commit |
---|
[2] | 69 | |
---|
[3] | 70 | Save change into the database if change are not done immediately. |
---|
| 71 | This should always be called as you don't know when change are applied. |
---|
[2] | 72 | |
---|
[3] | 73 | Return always true if database does not support any transaction. |
---|
[2] | 74 | |
---|
[3] | 75 | The driver should provides a _commit functions to save data. |
---|
[2] | 76 | |
---|
[3] | 77 | =cut |
---|
[2] | 78 | |
---|
[3] | 79 | sub commit { |
---|
| 80 | my ($self) = @_; |
---|
| 81 | return $self->can('_commit') ? $self->_commit : 1; |
---|
| 82 | } |
---|
[2] | 83 | |
---|
[3] | 84 | =head2 rollback |
---|
[2] | 85 | |
---|
[3] | 86 | If database support transaction, rollback changes. Return false |
---|
| 87 | if database does not support. |
---|
[2] | 88 | |
---|
[3] | 89 | If supported, driver should provides a _rollback functions |
---|
[2] | 90 | |
---|
[3] | 91 | =cut |
---|
[2] | 92 | |
---|
[3] | 93 | sub rollback { |
---|
| 94 | my ($self) = @_; |
---|
| 95 | return $self->can('_rollback') ? $self->_commit : 0; |
---|
| 96 | } |
---|
[2] | 97 | |
---|
[3] | 98 | 1; |
---|
[2] | 99 | |
---|
[3] | 100 | __END__ |
---|
[2] | 101 | |
---|
[3] | 102 | =head1 SEE ALSO |
---|
[2] | 103 | |
---|
| 104 | =head1 AUTHOR |
---|
| 105 | |
---|
[3] | 106 | Thauvin Olivier, E<lt>olivier.thauvin.ipsl.fr.thauvin@latmos.ipsl.fr<gt> |
---|
[2] | 107 | |
---|
| 108 | =head1 COPYRIGHT AND LICENSE |
---|
| 109 | |
---|
| 110 | Copyright (C) 2009 by Thauvin Olivier |
---|
| 111 | |
---|
| 112 | This library is free software; you can redistribute it and/or modify |
---|
| 113 | it under the same terms as Perl itself, either Perl version 5.10.0 or, |
---|
| 114 | at your option, any later version of Perl 5 you may have available. |
---|
| 115 | |
---|
| 116 | =cut |
---|