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

Last change on this file since 12 was 12, checked in by nanardon, 15 years ago
  • trape object->new return undef
  • add type functions
  • Property svn:keywords set to Id Rev
File size: 3.2 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 new($base, $type, $id, ...)
25
26Return a new object of type $type having unique identifier
27$id, all remaining arguments are passed to the subclass.
28
29=cut
30
31sub 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
42sub type {
43    my ($self) = @_;
44    return $self->{_type}
45}
46
47=head2 base
48
49Return the base handle for this object.
50
51=cut
52
53sub base {
54    return $_[0]->{_base}
55}
56
57=head2 _canonical_fields
58
59Must return the list of field supported by the object.
60
61Notice this query will always come from the upstream data base,
62this function is just a ficility to store data in the module, but the
63underling database can reply themself.
64
65See list_canonical_fields().
66
67=cut
68
69sub _canonical_fields { 
70    my ($self) = @_;
71    return;
72}
73
74=head2 _get_fields_name($field)
75
76Return the fields name for canonical field $field
77
78=cut
79
80sub _get_field_name {
81    my ($self, $field) = @_;
82    return;
83}
84
85=head2 get_field($field)
86
87Return the value for $field, must be provide by data base.
88
89=cut
90
91sub get_field { return }
92
93=head2 get_c_fields($cfield)
94
95Return the value for canonical field $cfield
96
97=cut
98
99sub 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
107Set values for this object. %data is a list or peer field => values.
108
109=cut
110
111sub set_fields {
112    return;
113}
114
115=head2 set_fields(%data)
116
117Set values for this object. %data is a list or peer
118canonical field => values. Fields names are translated.
119
120=cut
121
122sub 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
1331;
134
135__END__
136
137=head1 CANICALS FIELDS
138
139=head2 User class
140
141=head2 Group class
142
143=head1 SEE ALSO
144
145Mention other useful documentation such as the documentation of
146related modules or operating system documentation (such as man pages
147in UNIX), or any relevant external documentation such as RFCs or
148standards.
149
150If you have a mailing list set up for your module, mention it here.
151
152If you have a web site set up for your module, mention it here.
153
154=head1 AUTHOR
155
156Thauvin Olivier, E<lt>olivier.thauvin.ipsl.fr@localdomainE<gt>
157
158=head1 COPYRIGHT AND LICENSE
159
160Copyright (C) 2009 by Thauvin Olivier
161
162This library is free software; you can redistribute it and/or modify
163it under the same terms as Perl itself, either Perl version 5.10.0 or,
164at your option, any later version of Perl 5 you may have available.
165
166
167=cut
Note: See TracBrowser for help on using the repository browser.