Changeset 194

Show
Ignore:
Timestamp:
02/08/05 20:16:21 (4 years ago)
Author:
athomas
Message:

Added on_change() trigger for %CONF variables.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • manage/trunk/manage

    r193 r194  
    158158} 
    159159 
    160 sub get_password($) { 
     160sub read_password($) { 
    161161my $prompt = shift; 
    162162my $tty = ctermid(); 
     
    172172        close(TTY); 
    173173        return $secret; 
     174} 
     175 
     176sub get_password($) { 
     177        warning("get_password() is deprecated and will be removed, use read_password()"); 
     178        return read_password(@_); 
    174179} 
    175180 
     
    280285                        $_ =~ /^([.\w-]+)\s*=\s*(.*)/; 
    281286                        if (defined($CONF{$1})) { 
    282                                 ${$CONF{$1}->{value}} = $2; 
     287                                if ($CONF{$1}->{on_change}) { 
     288                                        ${$CONF{$1}->{value}} = $CONF{$1}->{on_change}->(${$CONF{$1}->{value}}, $2); 
     289                                } else { 
     290                                        ${$CONF{$1}->{value}} = $2; 
     291                                } 
     292                                $CONF{$1}->{loaded} = 1; 
    283293                        } 
    284294                } 
     
    310320                                                $pattern = '.+' unless defined($pattern); 
    311321                                                if ($value =~ /^$pattern$/) { 
    312                                                         ${$CONF{$key}->{value}} = $value; 
     322                                                        if ($CONF{$key}->{on_change}) { 
     323                                                                ${$CONF{$key}->{value}} = $CONF{$key}->{on_change}->(${$CONF{$key}->{value}}, $value); 
     324                                                        } else { 
     325                                                                ${$CONF{$key}->{value}} = $value; 
     326                                                        } 
    313327                                                } else { 
    314328                                                        error("Value for '$key' is invalid."); 
     
    411425 
    412426  Binary symlink: 
    413     $Config{bin}/$SELF -> $Config{bin}/$cli 
     427    $Config{bin}/$cli -> $Config{bin}/$SELF 
    414428  Modules: 
    415429EOF 
     
    509523 
    510524for my $key (keys %CONF) { 
     525        # We only trigger an on_change if this did not already occur in load_config() 
     526        ${$CONF{$key}->{value}} = $CONF{$key}->{on_change}->(${$CONF{$key}->{value}}, ${$CONF{$key}->{value}}) 
     527                if $CONF{$key}->{on_change} and not $CONF{$key}->{loaded}; 
    511528        $ORIGINAL_CONF{$key} = ${$CONF{$key}->{value}}; 
    512529}