3 # Obj -- basic object stuff
4 # Copyright (C) 2005 Erik van Konijnenburg
6 # This program is free software; you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation; either version 2 of the License, or
9 # (at your option) any later version.
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
16 # You should have received a copy of the GNU General Public License
17 # along with this program; if not, write to the Free Software
18 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 # The new() function takes a hash as argument, used to do object
21 # initialisation. Initialisation is delegated to fill() in derived
22 # classes. Fill() is expected to use takeArgs() to claim those
23 # initialisation args it's interested in; other args are left for
24 # fill() functions further down the inheritance chain. Arguments
25 # may have undef as value.
36 $self->{'_args'} = { @_ };
37 bless ($self, $class);
39 my $bad = join (', ', keys %{$self->{'_args'}});
41 Base::bug "Unknown constructor args: $bad";
48 # Derived classes can claim arguments like so:
49 # self->SUPER::fill();
50 # $self->takeArg ('a');
54 my ($self, @fields) = @_;
55 for my $field (@fields) {
56 Base::assert (exists ($self->{'_args'}{$field}));
57 $self->{$field} = delete $self->{'_args'}{$field};