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 new($base, $type, $id, ...) |
---|
25 | |
---|
26 | Return a new object of type $type having unique identifier |
---|
27 | $id, all remaining arguments are passed to the subclass. |
---|
28 | |
---|
29 | =cut |
---|
30 | |
---|
31 | sub new { |
---|
32 | my ($class, $base, $otype, $id, @args) = @_; |
---|
33 | |
---|
34 | # finding perl class: |
---|
35 | my $pclass = $base->_load_obj_class($otype) or return; |
---|
36 | my $newobj = "$pclass"->new($base, $id, @args) or return; |
---|
37 | $newobj->{_base} = $base; |
---|
38 | $newobj->{_type} = lc($otype); |
---|
39 | return $newobj; |
---|
40 | } |
---|
41 | |
---|
42 | sub type { |
---|
43 | my ($self) = @_; |
---|
44 | return $self->{_type} |
---|
45 | } |
---|
46 | |
---|
47 | =head2 base |
---|
48 | |
---|
49 | Return the base handle for this object. |
---|
50 | |
---|
51 | =cut |
---|
52 | |
---|
53 | sub base { |
---|
54 | return $_[0]->{_base} |
---|
55 | } |
---|
56 | |
---|
57 | =head2 _canonical_fields |
---|
58 | |
---|
59 | Must return the list of field supported by the object. |
---|
60 | |
---|
61 | Notice this query will always come from the upstream data base, |
---|
62 | this function is just a ficility to store data in the module, but the |
---|
63 | underling database can reply themself. |
---|
64 | |
---|
65 | See list_canonical_fields(). |
---|
66 | |
---|
67 | =cut |
---|
68 | |
---|
69 | sub _canonical_fields { |
---|
70 | my ($self) = @_; |
---|
71 | return; |
---|
72 | } |
---|
73 | |
---|
74 | =head2 _get_fields_name($field) |
---|
75 | |
---|
76 | Return the fields name for canonical field $field |
---|
77 | |
---|
78 | =cut |
---|
79 | |
---|
80 | sub _get_field_name { |
---|
81 | my ($self, $field) = @_; |
---|
82 | return; |
---|
83 | } |
---|
84 | |
---|
85 | =head2 get_field($field) |
---|
86 | |
---|
87 | Return the value for $field, must be provide by data base. |
---|
88 | |
---|
89 | =cut |
---|
90 | |
---|
91 | sub get_field { return } |
---|
92 | |
---|
93 | =head2 get_c_fields($cfield) |
---|
94 | |
---|
95 | Return the value for canonical field $cfield |
---|
96 | |
---|
97 | =cut |
---|
98 | |
---|
99 | sub get_c_field { |
---|
100 | my ($self, $cfield) = @_; |
---|
101 | my $field = $self->base->get_field_name($self->type, $cfield) or return; |
---|
102 | $self->get_field($field); |
---|
103 | } |
---|
104 | |
---|
105 | =head2 set_fields(%data) |
---|
106 | |
---|
107 | Set values for this object. %data is a list or peer field => values. |
---|
108 | |
---|
109 | =cut |
---|
110 | |
---|
111 | sub set_fields { |
---|
112 | return; |
---|
113 | } |
---|
114 | |
---|
115 | =head2 set_fields(%data) |
---|
116 | |
---|
117 | Set values for this object. %data is a list or peer |
---|
118 | canonical field => values. Fields names are translated. |
---|
119 | |
---|
120 | =cut |
---|
121 | |
---|
122 | sub set_c_fields { |
---|
123 | my ($self, %cdata) = @_; |
---|
124 | my %data; |
---|
125 | foreach my $cfield (keys %cdata) { |
---|
126 | my $field = $self->base->get_field_name($self->type, $cfield) or next; |
---|
127 | $data{$field} = $cdata{$cfield}; |
---|
128 | } |
---|
129 | keys %data or return 1; # TODO: return an error ? |
---|
130 | $self->set_fields(%data); |
---|
131 | } |
---|
132 | |
---|
133 | 1; |
---|
134 | |
---|
135 | __END__ |
---|
136 | |
---|
137 | =head1 CANICALS FIELDS |
---|
138 | |
---|
139 | =head2 User class |
---|
140 | |
---|
141 | =head2 Group class |
---|
142 | |
---|
143 | =head1 SEE ALSO |
---|
144 | |
---|
145 | Mention other useful documentation such as the documentation of |
---|
146 | related modules or operating system documentation (such as man pages |
---|
147 | in UNIX), or any relevant external documentation such as RFCs or |
---|
148 | standards. |
---|
149 | |
---|
150 | If you have a mailing list set up for your module, mention it here. |
---|
151 | |
---|
152 | If you have a web site set up for your module, mention it here. |
---|
153 | |
---|
154 | =head1 AUTHOR |
---|
155 | |
---|
156 | Thauvin Olivier, E<lt>olivier.thauvin.ipsl.fr@localdomainE<gt> |
---|
157 | |
---|
158 | =head1 COPYRIGHT AND LICENSE |
---|
159 | |
---|
160 | Copyright (C) 2009 by Thauvin Olivier |
---|
161 | |
---|
162 | This library is free software; you can redistribute it and/or modify |
---|
163 | it under the same terms as Perl itself, either Perl version 5.10.0 or, |
---|
164 | at your option, any later version of Perl 5 you may have available. |
---|
165 | |
---|
166 | |
---|
167 | =cut |
---|