1 | package LATMOS::Accounts::Bases::Objects; |
---|
2 | |
---|
3 | use 5.010000; |
---|
4 | use strict; |
---|
5 | use warnings; |
---|
6 | |
---|
7 | our $VERSION = (q$Rev$ =~ /^Rev: (\d+) /)[0]; |
---|
8 | |
---|
9 | =head1 NAME |
---|
10 | |
---|
11 | LATMOS::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 | |
---|
26 | List object supported by this module existing in base $base |
---|
27 | |
---|
28 | =cut |
---|
29 | |
---|
30 | sub list { |
---|
31 | my ($class) = @_; |
---|
32 | return; |
---|
33 | } |
---|
34 | |
---|
35 | =head2 new($base, $id) |
---|
36 | |
---|
37 | Create a new object having $id as uid. |
---|
38 | |
---|
39 | =cut |
---|
40 | |
---|
41 | sub 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 | |
---|
55 | sub _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 | |
---|
68 | Return the type of the object |
---|
69 | |
---|
70 | =cut |
---|
71 | |
---|
72 | sub type { |
---|
73 | my ($self) = @_; |
---|
74 | return $self->{_type} |
---|
75 | } |
---|
76 | |
---|
77 | =head2 base |
---|
78 | |
---|
79 | Return the base handle for this object. |
---|
80 | |
---|
81 | =cut |
---|
82 | |
---|
83 | sub base { |
---|
84 | return $_[0]->{_base} |
---|
85 | } |
---|
86 | |
---|
87 | =head2 _canonical_fields |
---|
88 | |
---|
89 | Must return the list of field supported by the object. |
---|
90 | |
---|
91 | Notice this query will always come from the upstream data base, |
---|
92 | this function is just a ficility to store data in the module, but the |
---|
93 | underling database can reply themself. |
---|
94 | |
---|
95 | See list_canonical_fields(). |
---|
96 | |
---|
97 | =cut |
---|
98 | |
---|
99 | sub _canonical_fields { |
---|
100 | my ($self) = @_; |
---|
101 | return; |
---|
102 | } |
---|
103 | |
---|
104 | =head2 _get_fields_name($field) |
---|
105 | |
---|
106 | Return the fields name for canonical field $field |
---|
107 | |
---|
108 | =cut |
---|
109 | |
---|
110 | sub _get_field_name { |
---|
111 | my ($self, $field) = @_; |
---|
112 | return; |
---|
113 | } |
---|
114 | |
---|
115 | =head2 get_field($field) |
---|
116 | |
---|
117 | Return the value for $field, must be provide by data base. |
---|
118 | |
---|
119 | =cut |
---|
120 | |
---|
121 | sub get_field { return } |
---|
122 | |
---|
123 | =head2 get_c_fields($cfield) |
---|
124 | |
---|
125 | Return the value for canonical field $cfield |
---|
126 | |
---|
127 | =cut |
---|
128 | |
---|
129 | sub 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 | |
---|
137 | Set values for this object. %data is a list or peer field => values. |
---|
138 | |
---|
139 | =cut |
---|
140 | |
---|
141 | sub set_fields { |
---|
142 | return; |
---|
143 | } |
---|
144 | |
---|
145 | =head2 set_fields(%data) |
---|
146 | |
---|
147 | Set values for this object. %data is a list or peer |
---|
148 | canonical field => values. Fields names are translated. |
---|
149 | |
---|
150 | =cut |
---|
151 | |
---|
152 | sub 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 | |
---|
163 | 1; |
---|
164 | |
---|
165 | __END__ |
---|
166 | |
---|
167 | =head1 CANICALS FIELDS |
---|
168 | |
---|
169 | =head2 User class |
---|
170 | |
---|
171 | =head2 Group class |
---|
172 | |
---|
173 | =head1 SEE ALSO |
---|
174 | |
---|
175 | Mention other useful documentation such as the documentation of |
---|
176 | related modules or operating system documentation (such as man pages |
---|
177 | in UNIX), or any relevant external documentation such as RFCs or |
---|
178 | standards. |
---|
179 | |
---|
180 | If you have a mailing list set up for your module, mention it here. |
---|
181 | |
---|
182 | If you have a web site set up for your module, mention it here. |
---|
183 | |
---|
184 | =head1 AUTHOR |
---|
185 | |
---|
186 | Thauvin Olivier, E<lt>olivier.thauvin.ipsl.fr@localdomainE<gt> |
---|
187 | |
---|
188 | =head1 COPYRIGHT AND LICENSE |
---|
189 | |
---|
190 | Copyright (C) 2009 by Thauvin Olivier |
---|
191 | |
---|
192 | This library is free software; you can redistribute it and/or modify |
---|
193 | it under the same terms as Perl itself, either Perl version 5.10.0 or, |
---|
194 | at your option, any later version of Perl 5 you may have available. |
---|
195 | |
---|
196 | |
---|
197 | =cut |
---|