source: LATMOS-Accounts/lib/LATMOS/Accounts.pm @ 41

Last change on this file since 41 was 41, checked in by nanardon, 15 years ago
  • start synchronisation work
  • Property svn:keywords set to Id Rev
File size: 2.8 KB
Line 
1package LATMOS::Accounts;
2
3use 5.010000;
4use strict;
5use warnings;
6use base qw(Config::IniFiles);
7use LATMOS::Accounts::Bases;
8
9our $VERSION = (q$Rev$ =~ /^Rev: (\d+) /)[0];
10
11sub new {
12    my ($class, $config) = @_;
13
14    $config ||= '/etc/latmos-account.ini';
15
16    my $self = Config::IniFiles->new(
17        -file => $config
18    );
19
20    bless($self, $class)
21}
22
23sub base {
24    my ($self, $section) = @_;
25    # this method perform a cache
26    $self->{_bases}{$section} and return $self->{_bases}{$section};
27    $self->load_base($section) ? $self->{_bases}{$section} : undef;
28}
29
30sub default_base {
31    my ($self) = @_;
32    my $default = $self->default_base_name or return;
33    $self->base($default);
34}
35
36# load or a if need base
37sub load_base {
38    my ($self, $section) = @_;
39    return ($self->{_bases}{$section} ||= $self->_load_base($section))
40        ? 1
41        : 0;
42}
43
44# do the bad work
45sub _load_base {
46    my ($self, $section) = @_;
47    my $type = $self->val($section, 'type') or return;
48    my %params = map { $_ => ($self->val($section, $_)) } $self->Parameters($section);
49    my $base = LATMOS::Accounts::Bases->new($type, %params);
50    $base->load or return;
51    $base;
52}
53
54sub default_base_name {
55    my ($self) = @_;
56    $self->val('_default_', 'base', ($self->list_bases)[0]);
57}
58
59sub list_bases {
60    my ($self) = @_;
61    grep {
62        !m/^_.*_$/
63    } $self->Sections
64}
65
66sub load_all_base {
67    my ($self) = @_;
68    foreach ($self->list_bases) {
69        $self->load_base($_) or do {
70            warn "Cannot load base $_\n";
71            return 0;
72        };
73    }
74    1;
75}
76
77sub config_sync_base {
78    my ($self, $from) = @_;
79    return split(/ /, $self->val($from, 'push', ''));
80} 
81
821;
83
84__END__
85# Below is stub documentation for your module. You'd better edit it!
86
87=head1 NAME
88
89LATMOS::Accounts - Perl extension for blah blah blah
90
91=head1 SYNOPSIS
92
93  use LATMOS::Accounts;
94  blah blah blah
95
96=head1 DESCRIPTION
97
98Stub documentation for LATMOS::Accounts, created by h2xs. It looks like the
99author of the extension was negligent enough to leave the stub
100unedited.
101
102Blah blah blah.
103
104=head2 EXPORT
105
106None by default.
107
108
109
110=head1 SEE ALSO
111
112Mention other useful documentation such as the documentation of
113related modules or operating system documentation (such as man pages
114in UNIX), or any relevant external documentation such as RFCs or
115standards.
116
117If you have a mailing list set up for your module, mention it here.
118
119If you have a web site set up for your module, mention it here.
120
121=head1 AUTHOR
122
123Thauvin Olivier, E<lt>olivier.thauvin@latmosipsl.frE<gt>
124
125=head1 COPYRIGHT AND LICENSE
126
127Copyright (C) 2009 by Thauvin Olivier
128
129This library is free software; you can redistribute it and/or modify
130it under the same terms as Perl itself, either Perl version 5.10.0 or,
131at your option, any later version of Perl 5 you may have available.
132
133
134=cut
Note: See TracBrowser for help on using the repository browser.