1package Typelib::Base; 2use Class::Std::Fast::Storable; 3 4sub mk_add_mutators { 5 my $class = shift; 6 my $attributes = shift; 7 for my $method ( keys %{$ attributes }) { 8 *{ "$class\::add_$method" } = sub { 9 my ($self, $value) = @_; 10 my $ident = ${ $self }; 11 12 # we're the first value 13 return $attributes->{ $method }->{ $ident } = $value 14 if not defined $attributes->{ $method }->{ $ident }; 15 16 # we're the second value 17 return $attributes->{ $method }->{ $ident } = [ 18 $attributes->{ $method }->{ $ident }, $value ] 19 if not ref $attributes->{ $method }->{ $ident } eq 'ARRAY'; 20 21 # we're third or later 22 push @{ $attributes->{ $method }->{ $ident } }, $value; 23 return $attributes->{ $method }->{ $ident }; 24 } 25 } 26} 27 281;