root/trunk/lib/Mungo/Arbiter.pm

Revision 42, 1.2 kB (checked in by jesus, 6 years ago)

refs #15. Need to test this extensively, but it behaves as expected in my cursory tests.

Line 
1 package Mungo::Arbiter;
2
3 # Copyright (c) 2007 OmniTI Computer Consulting, Inc. All rights reserved.
4 # For information on licensing see:
5 #   https://labs.omniti.com/zetaback/trunk/LICENSE
6
7 sub __immutable {
8   my ($self, $key) = @_;
9   die "Mungo '$key' is immutable!\n";
10   return 0;
11 }
12 sub __boolean {
13   my ($self, $key, $value) = @_;
14   return 1 if ($value =~ /^(?:0|1)$/);
15   return 0;
16 }
17 sub __coderef {
18   my ($self, $key, $value) = @_;
19   return (ref $value eq 'CODE') ? 1 : 0;
20 }
21 sub TIEHASH {
22   my $class = shift;
23   my $parent = shift;
24   my $data = shift;
25   return bless { '__Internal__' => $parent, data => $data }, $class;
26 }
27 sub UNTIE {
28   my $self = shift;
29   delete $self->{'__Internal__'};
30 }
31 sub FIRSTKEY {
32   my $self = shift;
33   my $a = keys %{$self->{data}};
34   return each %{$self->{data}};
35 }
36 sub NEXTKEY {
37   my $self = shift;
38   return each %{$self->{data}};
39 }
40 sub FETCH {
41   my $self = shift;
42   my $key = shift;
43   return $self->{data}->{$key};
44 }
45 sub EXISTS {
46   my $self = shift;
47   my $key = shift;
48   return exists $self->{data}->{$key};
49 }
50 sub DELETE { }
51 sub STORE {
52   my ($self, $key, $value) = @_;
53   my $cv = $self->check_map($key);
54   if(!$cv || $cv->($self,$key,$value)) {
55     $self->{data}->{$key} = $value;
56   }
57 }
58
59 1;
Note: See TracBrowser for help on using the browser.