[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 | |
---|
| 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 | |
---|
[2] | 31 | sub new { |
---|
[3] | 32 | my ($class, $base, $otype, $id, @args) = @_; |
---|
[2] | 33 | |
---|
| 34 | # finding perl class: |
---|
[6] | 35 | my $pclass = $base->_load_obj_class($otype) or return; |
---|
[12] | 36 | my $newobj = "$pclass"->new($base, $id, @args) or return; |
---|
[2] | 37 | $newobj->{_base} = $base; |
---|
[12] | 38 | $newobj->{_type} = lc($otype); |
---|
[2] | 39 | return $newobj; |
---|
| 40 | } |
---|
| 41 | |
---|
[12] | 42 | sub type { |
---|
| 43 | my ($self) = @_; |
---|
| 44 | return $self->{_type} |
---|
| 45 | } |
---|
| 46 | |
---|
[3] | 47 | =head2 base |
---|
[2] | 48 | |
---|
[3] | 49 | Return the base handle for this object. |
---|
| 50 | |
---|
| 51 | =cut |
---|
| 52 | |
---|
| 53 | sub base { |
---|
| 54 | return $_[0]->{_base} |
---|
| 55 | } |
---|
| 56 | |
---|
[7] | 57 | =head2 _canonical_fields |
---|
[2] | 58 | |
---|
[6] | 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 | |
---|
[7] | 69 | sub _canonical_fields { |
---|
[6] | 70 | my ($self) = @_; |
---|
[7] | 71 | return; |
---|
[6] | 72 | } |
---|
| 73 | |
---|
[7] | 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 | |
---|
[11] | 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 | |
---|
[8] | 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; |
---|
[11] | 125 | foreach my $cfield (keys %cdata) { |
---|
| 126 | my $field = $self->base->get_field_name($self->type, $cfield) or next; |
---|
| 127 | $data{$field} = $cdata{$cfield}; |
---|
[8] | 128 | } |
---|
| 129 | keys %data or return 1; # TODO: return an error ? |
---|
| 130 | $self->set_fields(%data); |
---|
| 131 | } |
---|
| 132 | |
---|
[2] | 133 | 1; |
---|
| 134 | |
---|
| 135 | __END__ |
---|
| 136 | |
---|
[6] | 137 | =head1 CANICALS FIELDS |
---|
| 138 | |
---|
| 139 | =head2 User class |
---|
| 140 | |
---|
| 141 | =head2 Group class |
---|
| 142 | |
---|
[2] | 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 | |
---|
[3] | 156 | Thauvin Olivier, E<lt>olivier.thauvin.ipsl.fr@localdomainE<gt> |
---|
[2] | 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 |
---|