Changeset 12403
- Timestamp:
- 05/26/08 03:08:14 (5 years ago)
- Files:
-
- 1 modified
Legend:
- Unmodified
- Added
- Removed
-
lang/perl/tiarra/branches/module-reload/main/ModuleManager.pm
r12334 r12403 10 10 use warnings; 11 11 use UNIVERSAL; 12 #use RunLoop;12 use Scalar::Util qw(refaddr); 13 13 use Tiarra::SharedMixin qw(shared shared_manager); 14 14 use Tiarra::ShorthandConfMixin; … … 23 23 24 24 sub _new { 25 shift->new(shift || RunLoop->shared);25 shift->new(shift || do { require RunLoop && RunLoop->shared }); 26 26 } 27 27 … … 37 37 mod_blacklist => {}, # 過去に正常動作しなかったモジュール。 38 38 updated_once => 0, # 過去にupdate_modulesが実行された事があるか。 39 mod_disposables => {}, # モジュールに関連づけられているタイマーとか。アンロードした後で全部捨てる。 39 40 }; 40 41 bless $obj,$class; … … 160 161 } 161 162 163 sub add_module_object { 164 my $this = shift->_this; 165 my ($modname, @disposables) = @_; 166 $modname = ref($modname) || $modname; 167 168 push @{$this->{mod_disposables}->{$modname}}, @disposables; 169 170 $this; 171 } 172 173 sub remove_module_object { 174 my $this = shift->_this; 175 my ($modname, @disposables) = @_; 176 $modname = ref($modname) || $modname; 177 178 return unless $this->{mod_disposables}->{$modname}; 179 180 my %targets = map { refaddr($_) => 1 } @disposables; 181 @{$this->{mod_disposables}->{$modname}} = 182 grep { !$targets{refaddr($_)} } @{$this->{mod_disposables}->{$modname}}; 183 184 $this; 185 } 186 187 sub _destruct_module_object { 188 my $this = shift->_this; 189 my $module = shift; # module instance or module name 190 my $modname = ref($module) || $module; 191 192 my $arr = delete $this->{mod_disposables}->{$modname}; 193 194 return unless $arr; 195 196 foreach my $object (@$arr) { 197 eval { 198 $object->module_destruct($module); 199 }; if ($@) { 200 $this->_runloop->notify_error($@); 201 } 202 } 203 204 $this; 205 } 206 162 207 sub update_modules { 163 208 # +で指定されたモジュール一覧を読み、modulesを再構成する。 … … 271 316 # 先に destruct して回る 272 317 foreach my $modname (reverse @mods_load_order) { 273 my $ idx = $loaded_mods_idx{$modname};274 if ( defined $idx) {318 my $mod = $loaded_mods{$modname}; 319 if ($mod) { 275 320 eval { 276 $ this->{modules}->[$idx]->destruct;321 $mod->destruct; 277 322 }; if ($@) { 278 323 $this->_runloop->notify_error($@); 279 324 } 325 $this->_destruct_module_object($mod); 280 326 } else { 281 327 eval { … … 284 330 $this->_runloop->notify_error($@); 285 331 } 332 $this->_destruct_module_object($modname); 286 333 } 287 334 } … … 359 406 # %loaded_modsに古い物が入っている場合は破棄した上、アンロードする。 360 407 my $modname = $_; 408 my $mod = $loaded_mods{$modname}; 361 409 $show_msg->("Module ".$modname." will be unloaded."); 362 if (defined $ loaded_mods{$modname}) {410 if (defined $mod) { 363 411 eval { 364 $ loaded_mods{$modname}->destruct;412 $mod->destruct; 365 413 }; if ($@) { 366 414 $this->_runloop->notify_error($@); 367 415 } 416 $this->_destruct_module_object($mod); 368 417 } 369 418 $this->_unload($_); … … 526 575 # 念のため古いやつは destruct しておく。エラーは無視。 527 576 eval { $oldmod->destruct }; 577 $this->_destruct_module_object($oldmod); 528 578 return undef; 529 579 } … … 535 585 # 念のため古いやつは destruct しておく。エラーは無視。 536 586 eval { $oldmod->destruct }; 587 $this->_destruct_module_object($oldmod); 537 588 return undef; 538 589 } … … 655 706 $key->destruct; 656 707 }; 708 $this->_destruct_module_object($key); 657 709 658 710 $this->_runloop->notify_msg(
![(please configure the [header_logo] section in trac.ini)](/share/chrome/site/your_project_logo.png)