[2] | 1 | package LATMOS::Accounts::Bases::Objects; |
---|
| 2 | |
---|
| 3 | use 5.010000; |
---|
| 4 | use strict; |
---|
| 5 | use warnings; |
---|
| 6 | |
---|
[3] | 7 | our $VERSION = (q$Rev$ =~ /^Rev: (\d+) /)[0]; |
---|
[2] | 8 | |
---|
[3] | 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 | |
---|
[28] | 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 | |
---|
[27] | 35 | =head2 new($base, $id) |
---|
[3] | 36 | |
---|
[27] | 37 | Create a new object having $id as uid. |
---|
[3] | 38 | |
---|
| 39 | =cut |
---|
| 40 | |
---|
[28] | 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 | |
---|
[27] | 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 { |
---|
[3] | 56 | my ($class, $base, $otype, $id, @args) = @_; |
---|
[2] | 57 | |
---|
| 58 | # finding perl class: |
---|
[6] | 59 | my $pclass = $base->_load_obj_class($otype) or return; |
---|
[12] | 60 | my $newobj = "$pclass"->new($base, $id, @args) or return; |
---|
[2] | 61 | $newobj->{_base} = $base; |
---|
[12] | 62 | $newobj->{_type} = lc($otype); |
---|
[2] | 63 | return $newobj; |
---|
| 64 | } |
---|
| 65 | |
---|
[28] | 66 | =head2 type |
---|
| 67 | |
---|
| 68 | Return the type of the object |
---|
| 69 | |
---|
| 70 | =cut |
---|
| 71 | |
---|
[12] | 72 | sub type { |
---|
| 73 | my ($self) = @_; |
---|
| 74 | return $self->{_type} |
---|
| 75 | } |
---|
| 76 | |
---|
[3] | 77 | =head2 base |
---|
[2] | 78 | |
---|
[3] | 79 | Return the base handle for this object. |
---|
| 80 | |
---|
| 81 | =cut |
---|
| 82 | |
---|
| 83 | sub base { |
---|
| 84 | return $_[0]->{_base} |
---|
| 85 | } |
---|
| 86 | |
---|
[7] | 87 | =head2 _canonical_fields |
---|
[2] | 88 | |
---|
[6] | 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 | |
---|
[7] | 99 | sub _canonical_fields { |
---|
[6] | 100 | my ($self) = @_; |
---|
[7] | 101 | return; |
---|
[6] | 102 | } |
---|
| 103 | |
---|
[7] | 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 | |
---|
[11] | 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 | |
---|
[8] | 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; |
---|
[11] | 155 | foreach my $cfield (keys %cdata) { |
---|
| 156 | my $field = $self->base->get_field_name($self->type, $cfield) or next; |
---|
| 157 | $data{$field} = $cdata{$cfield}; |
---|
[8] | 158 | } |
---|
| 159 | keys %data or return 1; # TODO: return an error ? |
---|
| 160 | $self->set_fields(%data); |
---|
| 161 | } |
---|
| 162 | |
---|
[2] | 163 | 1; |
---|
| 164 | |
---|
| 165 | __END__ |
---|
| 166 | |
---|
[6] | 167 | =head1 CANICALS FIELDS |
---|
| 168 | |
---|
| 169 | =head2 User class |
---|
| 170 | |
---|
| 171 | =head2 Group class |
---|
| 172 | |
---|
[2] | 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 | |
---|
[3] | 186 | Thauvin Olivier, E<lt>olivier.thauvin.ipsl.fr@localdomainE<gt> |
---|
[2] | 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 |
---|