Help for this page

Select Code to Download


  1. or download this
    sub name :lvalue { shift->name }
    
    # and later
    
    $object->name = 
      [qw/ random unvalidated value which breaks encapsulation /];
    
  2. or download this
    sub name {
      my $self = shift;
      return $self->{name} unless @_;
      $self->{name} = shift;
      return $self;
    }
    
  3. or download this
    sub set_name {
      my $self = shift;
      croak "set_name() requires a name, silly!" unless @_;
      $self->{name} = shift; # insert other validation here
    }
    
  4. or download this
    $object->name($name);
    $object->age($age);
    $object->id($id); # huh?
    
  5. or download this
    $object->set_name($name);
    $object->set_age($age);
    $object->set_id($id); # huh?