line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
# ----------------------------------------------------------------------------# |
2
|
|
|
|
|
|
|
# Object::Registrar # |
3
|
|
|
|
|
|
|
# # |
4
|
|
|
|
|
|
|
# Copyright (c) 2001-02 Arun Kumar U . # |
5
|
|
|
|
|
|
|
# All rights reserved. # |
6
|
|
|
|
|
|
|
# # |
7
|
|
|
|
|
|
|
# This program is free software; you can redistribute it and/or # |
8
|
|
|
|
|
|
|
# modify it under the same terms as Perl itself. # |
9
|
|
|
|
|
|
|
# ----------------------------------------------------------------------------# |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
package Object::Registrar; |
12
|
|
|
|
|
|
|
|
13
|
1
|
|
|
1
|
|
4054
|
use Object::NotFoundException; |
|
1
|
|
|
|
|
4
|
|
|
1
|
|
|
|
|
13
|
|
14
|
1
|
|
|
1
|
|
666
|
use Object::AlreadyBound; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
7
|
|
15
|
|
|
|
|
|
|
|
16
|
1
|
|
|
1
|
|
41
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
31
|
|
17
|
1
|
|
|
1
|
|
5
|
use vars qw($VERSION); |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
76
|
|
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
$VERSION = "0.01"; |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
## Ultra safe Class Attribute(s) :-) |
22
|
|
|
|
|
|
|
{ |
23
|
|
|
|
|
|
|
my %ClassData = |
24
|
|
|
|
|
|
|
( |
25
|
|
|
|
|
|
|
'Instance' => undef, |
26
|
|
|
|
|
|
|
'Debug' => 0, |
27
|
|
|
|
|
|
|
); |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
foreach my $datum (keys(%ClassData)) { |
30
|
1
|
|
|
1
|
|
5
|
no strict 'refs'; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
34
|
|
31
|
|
|
|
|
|
|
*$datum = sub { |
32
|
1
|
|
|
1
|
|
4
|
use strict 'refs'; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
1156
|
|
33
|
0
|
|
|
0
|
|
|
my ($self, $newvalue) = @_; |
34
|
0
|
0
|
|
|
|
|
$ClassData{$datum} = $newvalue if @_ > 1; |
35
|
0
|
|
|
|
|
|
return($ClassData{$datum}); |
36
|
|
|
|
|
|
|
}; |
37
|
|
|
|
|
|
|
} |
38
|
|
|
|
|
|
|
}; |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
sub _newInstance |
41
|
|
|
|
|
|
|
{ |
42
|
0
|
|
|
0
|
|
|
my ($proto) = shift; |
43
|
0
|
|
|
|
|
|
my ($self, $class); |
44
|
|
|
|
|
|
|
|
45
|
0
|
|
|
|
|
|
$self = {}; |
46
|
0
|
|
|
|
|
|
$self->{'registry'} = undef; |
47
|
0
|
|
0
|
|
|
|
$class = ref($proto) || $proto; |
48
|
|
|
|
|
|
|
|
49
|
0
|
|
|
|
|
|
bless($self, $class); |
50
|
0
|
|
|
|
|
|
return $self; |
51
|
|
|
|
|
|
|
} |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
sub new |
54
|
|
|
|
|
|
|
{ |
55
|
0
|
|
|
0
|
0
|
|
my ($self) = @_; |
56
|
|
|
|
|
|
|
|
57
|
0
|
|
|
|
|
|
my $instance = $self->Instance(); |
58
|
0
|
0
|
|
|
|
|
if (!defined($instance)) { |
59
|
0
|
|
|
|
|
|
$instance = $self->_newInstance(); |
60
|
0
|
|
|
|
|
|
$self->Instance($instance); |
61
|
|
|
|
|
|
|
} |
62
|
0
|
|
|
|
|
|
return($instance); |
63
|
|
|
|
|
|
|
} |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
sub _store |
66
|
|
|
|
|
|
|
{ |
67
|
0
|
|
|
0
|
|
|
my ($self, $name, $object) = @_; |
68
|
|
|
|
|
|
|
|
69
|
0
|
|
|
|
|
|
my $registrar = $self->getInstance(); |
70
|
0
|
|
|
|
|
|
$registrar->{'registry'}->{$name} = $object; |
71
|
|
|
|
|
|
|
} |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
sub _retrieve |
74
|
|
|
|
|
|
|
{ |
75
|
0
|
|
|
0
|
|
|
my ($self, $name) = @_; |
76
|
|
|
|
|
|
|
|
77
|
0
|
|
|
|
|
|
my $registrar = $self->getInstance(); |
78
|
0
|
|
|
|
|
|
return $registrar->{'registry'}->{$name}; |
79
|
|
|
|
|
|
|
} |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
sub _destroy |
82
|
|
|
|
|
|
|
{ |
83
|
0
|
|
|
0
|
|
|
my ($self, $name) = @_; |
84
|
|
|
|
|
|
|
|
85
|
0
|
|
|
|
|
|
my $registrar = $self->getInstance(); |
86
|
0
|
|
|
|
|
|
$registrar->{'registry'}->{$name} = undef; |
87
|
0
|
|
|
|
|
|
delete $registrar->{'registry'}->{$name}; |
88
|
|
|
|
|
|
|
} |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
sub exists |
91
|
|
|
|
|
|
|
{ |
92
|
0
|
|
|
0
|
1
|
|
my ($self, $name) = @_; |
93
|
|
|
|
|
|
|
|
94
|
0
|
|
|
|
|
|
my $registrar = $self->getInstance(); |
95
|
0
|
0
|
|
|
|
|
if (exists($registrar->{'registry'}->{$name})) { return 1; } |
|
0
|
|
|
|
|
|
|
96
|
0
|
|
|
|
|
|
else { return 0; } |
97
|
|
|
|
|
|
|
} |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
sub getContexts |
100
|
|
|
|
|
|
|
{ |
101
|
0
|
|
|
0
|
0
|
|
my ($self) = @_; |
102
|
|
|
|
|
|
|
|
103
|
0
|
|
|
|
|
|
my $registrar = $self->getInstance(); |
104
|
0
|
|
|
|
|
|
return keys(%{$registrar->{'registry'}}); |
|
0
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
} |
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
sub bind |
108
|
|
|
|
|
|
|
{ |
109
|
0
|
|
|
0
|
1
|
|
my ($self, $name, $object) = @_; |
110
|
|
|
|
|
|
|
|
111
|
0
|
0
|
|
|
|
|
if ($self->exists($name)) { |
112
|
0
|
|
|
|
|
|
throw Object::AlreadyBound("Object already bound with the name \"$name\"\n"); |
113
|
|
|
|
|
|
|
} |
114
|
0
|
|
|
|
|
|
else { $self->_store($name, $object); } |
115
|
0
|
0
|
|
|
|
|
print STDERR "Bound \"$name\" [$object] with Registrar\n" if ($self->Debug()); |
116
|
|
|
|
|
|
|
} |
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
sub rebind |
119
|
|
|
|
|
|
|
{ |
120
|
0
|
|
|
0
|
1
|
|
my ($self, $name, $object) = @_; |
121
|
|
|
|
|
|
|
|
122
|
0
|
|
|
|
|
|
$self->_store($name, $object); |
123
|
0
|
0
|
|
|
|
|
print STDERR "Bound \"$name\" [$object] with Registrar\n" if ($self->Debug()); |
124
|
|
|
|
|
|
|
} |
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
sub unbind |
127
|
|
|
|
|
|
|
{ |
128
|
0
|
|
|
0
|
1
|
|
my ($self, $name) = @_; |
129
|
|
|
|
|
|
|
|
130
|
0
|
|
|
|
|
|
$self->_destroy($name); |
131
|
0
|
0
|
|
|
|
|
print STDERR "Unbound \"$name\" from Registrar\n" if ($self->Debug()); |
132
|
|
|
|
|
|
|
} |
133
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
sub resolve |
135
|
|
|
|
|
|
|
{ |
136
|
0
|
|
|
0
|
1
|
|
my ($self, $name) = @_; |
137
|
|
|
|
|
|
|
|
138
|
0
|
0
|
|
|
|
|
if (!$self->exists($name)) { |
139
|
0
|
|
|
|
|
|
throw Object::NotFoundException("Object \"$name\" not found\n"); |
140
|
|
|
|
|
|
|
} |
141
|
|
|
|
|
|
|
|
142
|
0
|
|
|
|
|
|
my $object = $self->_retrieve($name); |
143
|
0
|
0
|
|
|
|
|
if (!$object) { |
144
|
0
|
|
|
|
|
|
throw Object::NotFoundException("Object \"$name\" not found\n"); |
145
|
|
|
|
|
|
|
} |
146
|
0
|
|
|
|
|
|
return($object); |
147
|
|
|
|
|
|
|
} |
148
|
|
|
|
|
|
|
|
149
|
|
|
|
|
|
|
sub list |
150
|
|
|
|
|
|
|
{ |
151
|
0
|
|
|
0
|
1
|
|
my ($self, $pattern) = @_; |
152
|
0
|
|
|
|
|
|
my (%objhash); |
153
|
|
|
|
|
|
|
|
154
|
0
|
|
|
|
|
|
my @keys = $self->getContexts(); |
155
|
0
|
|
|
|
|
|
foreach my $key (@keys) { |
156
|
0
|
0
|
|
|
|
|
if ($key =~ m/^${pattern}$/) { |
157
|
0
|
|
|
|
|
|
$objhash{$key} = $self->_retrieve($key); |
158
|
|
|
|
|
|
|
} |
159
|
|
|
|
|
|
|
} |
160
|
0
|
|
|
|
|
|
return %objhash; |
161
|
|
|
|
|
|
|
} |
162
|
|
|
|
|
|
|
|
163
|
|
|
|
|
|
|
# Just to stop perl -cw from complaining |
164
|
|
|
|
|
|
|
sub getInstance; |
165
|
|
|
|
|
|
|
sub register; |
166
|
|
|
|
|
|
|
sub reregister; |
167
|
|
|
|
|
|
|
sub unregister; |
168
|
|
|
|
|
|
|
|
169
|
|
|
|
|
|
|
## Some useful method aliases |
170
|
|
|
|
|
|
|
*getInstance = \&new; |
171
|
|
|
|
|
|
|
*register = \&bind; |
172
|
|
|
|
|
|
|
*reregister = \&rebind; |
173
|
|
|
|
|
|
|
*unregister = \&unbind; |
174
|
|
|
|
|
|
|
|
175
|
|
|
|
|
|
|
1; |
176
|
|
|
|
|
|
|
|
177
|
|
|
|
|
|
|
__END__; |