source: LATMOS-Accounts/lib/LATMOS/Accounts/Bases/Objects.pm @ 28

Last change on this file since 28 was 28, checked in by nanardon, 15 years ago
  • add list_objects() functions
  • Property svn:keywords set to Id Rev
File size: 3.6 KB
Line 
1package LATMOS::Accounts::Bases::Objects;
2
3use 5.010000;
4use strict;
5use warnings;
6
7our $VERSION = (q$Rev$ =~ /^Rev: (\d+) /)[0];
8
9=head1 NAME
10
11LATMOS::Accounts::Bases::Objects - Base class for account objects
12
13=head1 SYNOPSIS
14
15  use LATMOS::Accounts::Bases::Objects;
16  LATMOS::Accounts::Bases::Objects->new($base, $type, $id);
17
18=head1 DESCRIPTION
19
20=head1 FUNCTIONS
21
22=cut
23
24=head2 list($base)
25
26List object supported by this module existing in base $base
27
28=cut
29
30sub list {
31    my ($class) = @_;
32    return;
33}
34
35=head2 new($base, $id)
36
37Create a new object having $id as uid.
38
39=cut
40
41sub new {
42    my ($class, $base, $id, @args) = @_;
43    # So can be call as $class->SUPER::new()
44    bless {
45        _base => $base,
46        _type => ($class =~ m/[^:]*$/)[0],
47    }, $class;
48}
49
50# _new($base, $type, $id, ...)
51
52# Return a new object of type $type having unique identifier
53# $id, all remaining arguments are passed to the subclass.
54
55sub _new {
56    my ($class, $base, $otype, $id, @args) = @_;
57
58    # finding perl class:
59    my $pclass = $base->_load_obj_class($otype) or return;
60    my $newobj = "$pclass"->new($base, $id, @args) or return;
61    $newobj->{_base} = $base;
62    $newobj->{_type} = lc($otype);
63    return $newobj;
64}
65
66=head2 type
67
68Return the type of the object
69
70=cut
71
72sub type {
73    my ($self) = @_;
74    return $self->{_type}
75}
76
77=head2 base
78
79Return the base handle for this object.
80
81=cut
82
83sub base {
84    return $_[0]->{_base}
85}
86
87=head2 _canonical_fields
88
89Must return the list of field supported by the object.
90
91Notice this query will always come from the upstream data base,
92this function is just a ficility to store data in the module, but the
93underling database can reply themself.
94
95See list_canonical_fields().
96
97=cut
98
99sub _canonical_fields { 
100    my ($self) = @_;
101    return;
102}
103
104=head2 _get_fields_name($field)
105
106Return the fields name for canonical field $field
107
108=cut
109
110sub _get_field_name {
111    my ($self, $field) = @_;
112    return;
113}
114
115=head2 get_field($field)
116
117Return the value for $field, must be provide by data base.
118
119=cut
120
121sub get_field { return }
122
123=head2 get_c_fields($cfield)
124
125Return the value for canonical field $cfield
126
127=cut
128
129sub get_c_field {
130    my ($self, $cfield) = @_;
131    my $field = $self->base->get_field_name($self->type, $cfield) or return;
132    $self->get_field($field);
133}
134
135=head2 set_fields(%data)
136
137Set values for this object. %data is a list or peer field => values.
138
139=cut
140
141sub set_fields {
142    return;
143}
144
145=head2 set_fields(%data)
146
147Set values for this object. %data is a list or peer
148canonical field => values. Fields names are translated.
149
150=cut
151
152sub set_c_fields {
153    my ($self, %cdata) = @_;
154    my %data;
155    foreach my $cfield (keys %cdata) {
156        my $field = $self->base->get_field_name($self->type, $cfield) or next;
157        $data{$field} = $cdata{$cfield};
158    }
159    keys %data or return 1; # TODO: return an error ?
160    $self->set_fields(%data);
161}
162
1631;
164
165__END__
166
167=head1 CANICALS FIELDS
168
169=head2 User class
170
171=head2 Group class
172
173=head1 SEE ALSO
174
175Mention other useful documentation such as the documentation of
176related modules or operating system documentation (such as man pages
177in UNIX), or any relevant external documentation such as RFCs or
178standards.
179
180If you have a mailing list set up for your module, mention it here.
181
182If you have a web site set up for your module, mention it here.
183
184=head1 AUTHOR
185
186Thauvin Olivier, E<lt>olivier.thauvin.ipsl.fr@localdomainE<gt>
187
188=head1 COPYRIGHT AND LICENSE
189
190Copyright (C) 2009 by Thauvin Olivier
191
192This library is free software; you can redistribute it and/or modify
193it under the same terms as Perl itself, either Perl version 5.10.0 or,
194at your option, any later version of Perl 5 you may have available.
195
196
197=cut
Note: See TracBrowser for help on using the repository browser.