Changeset 12490

Show
Ignore:
Timestamp:
05/27/08 02:09:49 (5 years ago)
Author:
topia
Message:

* use weakref.

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • lang/perl/tiarra/branches/module-reload/main/ModuleManager.pm

    r12403 r12490  
    1010use warnings; 
    1111use UNIVERSAL; 
    12 use Scalar::Util qw(refaddr); 
     12use Scalar::Util qw(refaddr weaken); 
    1313use Tiarra::SharedMixin qw(shared shared_manager); 
    1414use Tiarra::ShorthandConfMixin; 
     
    2929    my ($class, $runloop) = @_; 
    3030    croak 'runloop is not specified!' unless defined $runloop; 
     31    weaken($runloop); 
    3132    my $obj = { 
    3233        runloop => $runloop, 
     
    166167    $modname = ref($modname) || $modname; 
    167168 
    168     push @{$this->{mod_disposables}->{$modname}}, @disposables; 
     169    my ($foo); 
     170    push @{$this->{mod_disposables}->{$modname}}, 
     171        map { $foo = \$_; weaken($_); $foo } @disposables; 
    169172 
    170173    $this; 
     
    178181    return unless $this->{mod_disposables}->{$modname}; 
    179182 
     183    my $arr = $this->{mod_disposables}->{$modname}; 
     184    @$arr = grep { defined $$_ } @$arr; 
     185 
    180186    my %targets = map { refaddr($_) => 1 } @disposables; 
    181     @{$this->{mod_disposables}->{$modname}} = 
    182         grep { !$targets{refaddr($_)} } @{$this->{mod_disposables}->{$modname}}; 
     187    @$arr = grep { !$targets{refaddr($$_)} } @$arr; 
     188 
     189    if (!@$arr) { 
     190        delete $this->{mod_disposables}->{$modname}; 
     191    } 
    183192 
    184193    $this; 
     
    196205    foreach my $object (@$arr) { 
    197206        eval { 
    198             $object->module_destruct($module); 
     207            $$object->module_destruct($module); 
    199208        }; if ($@) { 
    200209            $this->_runloop->notify_error($@);