Changeset 936 for LATMOS-Accounts


Ignore:
Timestamp:
04/25/12 15:51:27 (12 years ago)
Author:
nanardon
Message:
  • add get/set functions to attributes to get ride of get_field/set_field exceptions
Location:
LATMOS-Accounts/lib/LATMOS/Accounts/Bases
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • LATMOS-Accounts/lib/LATMOS/Accounts/Bases/Attributes.pm

    r933 r936  
    206206sub delayed { $_[0]->{delayed} || 0 } 
    207207 
     208=head2 get($attr) 
     209 
     210Return the value for this attribute 
     211 
     212=cut 
     213 
     214sub 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 
     224sub 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 
    2082341; 
  • LATMOS-Accounts/lib/LATMOS/Accounts/Bases/Objects.pm

    r934 r936  
    213213sub _get_c_field { 
    214214    my ($self, $cfield) = @_; 
    215     my $return; 
    216215    my $attribute = $self->attribute($cfield) or do { 
    217216        $self->base->log(LA_WARN, "Unknow attribute $cfield"); 
     
    222221        return; 
    223222    }; 
    224     $return = $self->get_field($attribute->iname); 
     223    return $attribute->get;  
    225224} 
    226225 
     
    290289    my ($self, %cdata) = @_; 
    291290    my %data; 
     291    my $res = 0; 
    292292    foreach my $cfield (keys %cdata) { 
    293293        my $attribute = $self->attribute($cfield) or do { 
     
    310310                "%s attribute cannot be empty, ignoring for object %s/%s", 
    311311                $cfield, 
    312                 $self->type, 
    313                 $self->id, 
     312                        $self->type, 
     313                        $self->id, 
    314314            ); 
    315315            return 0; 
    316316        }; 
    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 
    333321} 
    334322 
Note: See TracChangeset for help on using the changeset viewer.