Changeset 936 for LATMOS-Accounts
- Timestamp:
- 04/25/12 15:51:27 (12 years ago)
- Location:
- LATMOS-Accounts/lib/LATMOS/Accounts/Bases
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
LATMOS-Accounts/lib/LATMOS/Accounts/Bases/Attributes.pm
r933 r936 206 206 sub delayed { $_[0]->{delayed} || 0 } 207 207 208 =head2 get($attr) 209 210 Return the value for this attribute 211 212 =cut 213 214 sub get { 215 my ($self) = @_; 216 217 if (ref $self->{get} eq 'CODE') { 218 return $self->{get}->($self); 219 } else { 220 return $self->object->get_field($self->iname); 221 } 222 } 223 224 sub set { 225 my ($self, $values) = @_; 226 227 if (ref $self->{set} eq 'CODE') { 228 return $self->{set}->($self, $values); 229 } else { 230 return $self->object->set_fields($self->iname, $self->input($values)); 231 } 232 } 233 208 234 1; -
LATMOS-Accounts/lib/LATMOS/Accounts/Bases/Objects.pm
r934 r936 213 213 sub _get_c_field { 214 214 my ($self, $cfield) = @_; 215 my $return;216 215 my $attribute = $self->attribute($cfield) or do { 217 216 $self->base->log(LA_WARN, "Unknow attribute $cfield"); … … 222 221 return; 223 222 }; 224 $return = $self->get_field($attribute->iname);223 return $attribute->get; 225 224 } 226 225 … … 290 289 my ($self, %cdata) = @_; 291 290 my %data; 291 my $res = 0; 292 292 foreach my $cfield (keys %cdata) { 293 293 my $attribute = $self->attribute($cfield) or do { … … 310 310 "%s attribute cannot be empty, ignoring for object %s/%s", 311 311 $cfield, 312 $self->type,313 $self->id,312 $self->type, 313 $self->id, 314 314 ); 315 315 return 0; 316 316 }; 317 if (ref $cdata{$cfield}) { 318 $data{$attribute->iname} = []; # ensure hash entry exists 319 foreach (@{$cdata{$cfield}}) { 320 push(@{$data{$attribute->iname}}, defined($_) 321 ? $attribute->input($_) 322 : undef 323 ); 324 } 325 } else { 326 $data{$attribute->iname} = defined($cdata{$cfield}) 327 ? $attribute->input($cdata{$cfield}) 328 : undef; 329 } 330 } 331 keys %data or return 0; # TODO: return an error ? 332 $self->set_fields(%data); 317 $res += $attribute->set($cdata{$cfield}); 318 319 } 320 $res 333 321 } 334 322
Note: See TracChangeset
for help on using the changeset viewer.