2 |
## $Id$ |
## $Id$ |
3 |
## ------------------------------------------------------------------------ |
## ------------------------------------------------------------------------ |
4 |
## $Log$ |
## $Log$ |
5 |
|
## Revision 1.3 2002/12/27 16:06:55 joko |
6 |
|
## + sub _checkRequired |
7 |
|
## + sub getPossibleOptionKeys |
8 |
|
## + sub get |
9 |
|
## |
10 |
## Revision 1.2 2002/12/23 04:27:03 joko |
## Revision 1.2 2002/12/23 04:27:03 joko |
11 |
## + refactored, more oo-style now |
## + refactored, more oo-style now |
12 |
## |
## |
43 |
bless $self, $class; |
bless $self, $class; |
44 |
|
|
45 |
#my $fields = shift; |
#my $fields = shift; |
46 |
my @fields = @_; |
my @fields; |
47 |
|
foreach (@_) { |
48 |
|
if (ref $_ eq 'HASH') { |
49 |
|
$self->{__metadata} = $_; |
50 |
|
} else { |
51 |
|
push @fields, $_; |
52 |
|
} |
53 |
|
} |
54 |
|
|
55 |
# build mapping (hash with argument as key and callback (CODEref) as value) |
# build mapping (hash with argument as key and callback (CODEref) as value) |
56 |
$self->{__possible} = []; |
$self->{__possible} = []; |
78 |
# for convenience: store inside object itself, too |
# for convenience: store inside object itself, too |
79 |
$self->{$key} = $opt->{$key}; |
$self->{$key} = $opt->{$key}; |
80 |
} |
} |
81 |
|
|
82 |
|
$self->_checkRequired(); |
83 |
|
|
84 |
return $self; |
return $self; |
85 |
} |
} |
86 |
|
|
87 |
|
sub _checkRequired { |
88 |
|
my $self = shift; |
89 |
|
foreach (keys %{$self->{__metadata}->{required}}) { |
90 |
|
if (!$self->{__result}->{$_}) { |
91 |
|
$self->{__metadata}->{required}->{$_}->($self); |
92 |
|
} |
93 |
|
} |
94 |
|
} |
95 |
|
|
96 |
sub getOptions { |
sub getOptions { |
97 |
my $self = shift; |
my $self = shift; |
98 |
return $self->{__result}; |
return $self->{__result}; |
99 |
} |
} |
100 |
|
|
101 |
|
sub getPossibleOptionKeys { |
102 |
|
my $self = shift; |
103 |
|
return $self->{__possible}; |
104 |
|
} |
105 |
|
|
106 |
|
sub get { |
107 |
|
my $self = shift; |
108 |
|
my $key = shift; |
109 |
|
return $self->{$key}; |
110 |
|
} |
111 |
|
|
112 |
1; |
1; |