Changeset 177

Show
Ignore:
Timestamp:
02/25/07 11:03:39 (2 years ago)
Author:
ingy
Message:
 r3466@skinny-2:  ingy | 2007-02-25 11:02:43 -0800
 Found a good refactoring for Config creation. Removed a bunch of unneeded
 code.
Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/src/core/Kwiki/lib/Kwiki/Boot/V1.pm

    r175 r177  
    1616    $self->config->add_file('config.yaml'); 
    1717    for my $filepath (glob 'config*.*') { 
    18         $self->config->add_override_filepath($filepath); 
     18        $self->config->add_config($filepath, 1); 
    1919    } 
    2020} 
  • trunk/src/core/Spoon/lib/Spoon/Config.pm

    r175 r177  
    44const class_id => 'config'; 
    55field plugin_classes => []; 
    6 field overrides => {}; 
    76 
    87sub all { 
    98    return %$self; 
    10 } 
    11  
    12 sub add_override_filepath { 
    13     my $filepath = shift; 
    14     my $hash = $self->hash_from_file($filepath); 
    15     my $overrides = $self->overrides; 
    16     $overrides->{$_} = $hash->{$_} for keys %$hash; 
    17     $self->add_config($hash); 
    189} 
    1910 
     
    2213    for my $dir ($self->hub->paths->all_filepaths('config')) { 
    2314        my $filepath = "$dir/$file"; 
    24         $self->add_filepath($filepath
     15        $self->add_config($filepath, @_
    2516          if -f $filepath; 
    2617    } 
    2718} 
    2819 
    29 sub add_filepath { 
    30     my $filepath = shift; 
    31     my $hash = $self->hash_from_file($filepath); 
    32     $self->add_config($hash); 
    33     $self->add_config($self->overrides); 
    34 } 
    35  
    36 # sub add_field { 
    37 #     my ($field, $value) = @_; 
    38 #     field $field; 
    39 #     $self->{$field} = $value; 
    40 # } 
    41  
    4220sub add_config { 
    4321    my $config = shift; 
     22    my $override = shift || 0; 
    4423    my $hash = ref $config 
    4524    ? $config 
     
    4726    for my $key (keys %$hash) { 
    4827        field $key; 
    49         $self->{$key} = $hash->{$key}; 
     28        if ($override || not defined $self->{$key}) { 
     29            $self->{$key} = $hash->{$key}; 
     30        } 
    5031    } 
    5132    return $hash;