| 1 |
package Atheme::ReadOnlyHashWrapper; |
| 2 |
|
| 3 |
use Carp; |
| 4 |
|
| 5 |
sub TIEHASH { |
| 6 |
my ($class, $find_func) = @_; |
| 7 |
$class = ref $class || $class; |
| 8 |
|
| 9 |
my $self = { find_func => $find_func }; |
| 10 |
|
| 11 |
return bless $self, $class; |
| 12 |
} |
| 13 |
|
| 14 |
sub FETCH { |
| 15 |
my ($self, $key) = @_; |
| 16 |
|
| 17 |
return $self->{find_func}->($key); |
| 18 |
} |
| 19 |
|
| 20 |
sub readonly { |
| 21 |
croak "Attempted to modify read-only hash\n"; |
| 22 |
} |
| 23 |
|
| 24 |
sub STORE { goto &readonly; } |
| 25 |
sub DELETE { goto &readonly; } |
| 26 |
sub CLEAR { goto &readonly; } |
| 27 |
|
| 28 |
sub EXISTS { |
| 29 |
my ($self, $key) = @_; |
| 30 |
|
| 31 |
return defined $self->FETCH($key); |
| 32 |
} |
| 33 |
|
| 34 |
sub unimplemented { |
| 35 |
croak "Iteration over Atheme object hash not yet implemented\n"; |
| 36 |
} |
| 37 |
|
| 38 |
sub FIRSTKEY { goto &unimplemented; } |
| 39 |
sub NEXTKEY { goto &unimplemented; } |
| 40 |
|
| 41 |
sub SCALAR { |
| 42 |
return 1; # Generic true value. There's always at least one client. |
| 43 |
} |
| 44 |
|
| 45 |
1; |