ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/server/lib/cf.pm
(Generate patch)

Comparing deliantra/server/lib/cf.pm (file contents):
Revision 1.35 by root, Thu Aug 24 13:35:48 2006 UTC vs.
Revision 1.36 by root, Thu Aug 24 14:04:29 2006 UTC

231 1 231 1
232 } or warn "$ext not loaded: $@"; 232 } or warn "$ext not loaded: $@";
233 } 233 }
234} 234}
235 235
236sub _perl_reload(&) {
237 my ($msg) = @_;
238
239 $msg->("reloading...");
240
241 eval {
242 # 1. cancel all watchers
243 $_->cancel for Event::all_watchers;
244
245 # 2. unload all extensions
246 for (@exts) {
247 $msg->("unloading <$_>");
248 unload_extension $_;
249 }
250
251 # 3. unload all modules loaded from $LIBDIR
252 while (my ($k, $v) = each %INC) {
253 next unless $v =~ /^\Q$LIBDIR\E\/.*\.pm$/;
254
255 $msg->("removing <$k>");
256 delete $INC{$k};
257
258 $k =~ s/\.pm$//;
259 $k =~ s/\//::/g;
260
261 if (my $cb = $k->can ("unload_module")) {
262 $cb->();
263 }
264
265 Symbol::delete_package $k;
266 }
267
268 # 4. get rid of ext::, as good as possible
269 Symbol::delete_package "ext::$_"
270 for qw(cf::object cf::object::map cf::object::player cf::player cf::map cf::party cf::region);
271
272 # 5. remove register_script_function callbacks
273 # TODO
274
275 # 6. unload cf.pm "a bit"
276 delete $INC{"cf.pm"};
277
278 # don't, removes xs symbols, too
279 #Symbol::delete_package __PACKAGE__;
280
281 # 7. reload cf.pm
282 $msg->("reloading cf.pm");
283 require cf;
284 };
285 $msg->($@) if $@;
286
287 $msg->("reloaded");
288};
289
290sub perl_reload() {
291 _perl_reload {
292 warn $_[0];
293 print "$_[0]\n";
294 };
295}
296
236register_command "perl-reload", 0, sub { 297register_command "perl-reload", 0, sub {
237 my ($who, $arg) = @_; 298 my ($who, $arg) = @_;
238 299
239 if ($who->flag (FLAG_WIZ)) { 300 if ($who->flag (FLAG_WIZ)) {
240 $who->message ("reloading..."); 301 _perl_reload {
241 302 warn $_[0];
242 warn "reloading...\n"; 303 $who->message ($_[0]);
243 eval {
244 # 1. cancel all watchers
245 $_->cancel for Event::all_watchers;
246
247 # 2. unload all extensions
248 for (@exts) {
249 $who->message ("unloading <$_>");
250 unload_extension $_;
251 }
252
253 # 3. unload all modules loaded from $LIBDIR
254 while (my ($k, $v) = each %INC) {
255 next unless $v =~ /^\Q$LIBDIR\E\/.*\.pm$/;
256
257 $who->message ("removing <$k>");
258 delete $INC{$k};
259
260 $k =~ s/\.pm$//;
261 $k =~ s/\//::/g;
262
263 if (my $cb = $k->can ("unload_module")) {
264 $cb->();
265 }
266
267 Symbol::delete_package $k;
268 }
269
270 # 4. get rid of ext::, as good as possible
271 Symbol::delete_package "ext::$_"
272 for qw(cf::object cf::object::map cf::object::player cf::player cf::map cf::party cf::region);
273
274 # 5. remove register_script_function callbacks
275 # TODO
276
277 # 6. unload cf.pm "a bit"
278 delete $INC{"cf.pm"};
279
280 # don't, removes xs symbols, too
281 #Symbol::delete_package __PACKAGE__;
282
283 # 7. reload cf.pm
284 $who->message ("reloading cf.pm");
285 require cf;
286 }; 304 };
287 warn $@ if $@;
288 $who->message ($@) if $@;
289 warn "reloaded\n";
290
291 $who->message ("reloaded");
292 } else {
293 $who->message ("Intruder Alert!");
294 } 305 }
295}; 306};
296 307
297############################################################################# 308#############################################################################
298# utility functions 309# utility functions

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines