Changeset 352

Show
Ignore:
Timestamp:
03/06/06 21:53:56
Author:
ko
Message:

Implemented to "include:" and "recipe:" and "define_recipes:" directive in YAML file

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/plagger/lib/Plagger.pm

    r316 r352  
    4444    if (-e $opt{config} && -r _) { 
    4545        $config = YAML::LoadFile($opt{config}); 
     46        $self->load_include($config); 
    4647        $self->{conf} = $config->{global}; 
    4748        $self->{conf}->{log}   ||= { level => 'debug' }; 
     
    5253    local *Plagger::context = sub { $self }; 
    5354 
     55    $self->load_recipes($config); 
    5456    $self->load_cache($opt{config}); 
    5557    $self->load_plugins(@{ $config->{plugins} || [] }); 
    5658    $self->run(); 
     59} 
     60 
     61sub load_include { 
     62    my($self, $config) = @_; 
     63 
     64    return unless $config->{include}; 
     65    for (@{ $config->{include} }) { 
     66        my $include = YAML::LoadFile($_); 
     67 
     68        for my $key (keys %{ $include }) { 
     69            my $add = $include->{$key}; 
     70            unless ($config->{$key}) { 
     71                $config->{$key} = $add; 
     72                next; 
     73            } 
     74            if (ref($config->{$key}) eq 'HASH') { 
     75                next unless ref($add) eq 'HASH'; 
     76                for (keys %{ $include->{$key} }) { 
     77                    $config->{$key}->{$_} = $include->{$key}->{$_}; 
     78                } 
     79            } elsif (ref($include->{$key}) eq 'ARRAY') { 
     80                $add = [ $add ] unless ref($add) eq 'ARRAY'; 
     81                push(@{ $config->{$key} }, @{ $include->{$key} }); 
     82            } elsif ($add) { 
     83                $config->{$key} = $add; 
     84            } 
     85        } 
     86    } 
     87} 
     88 
     89sub load_recipes { 
     90    my($self, $config) = @_; 
     91 
     92    for (@{ $config->{define_recipes} }) { 
     93        $self->error("no such recipe to $_") unless $config->{recipe}->{$_}; 
     94        my $plugin = $config->{recipe}->{$_}; 
     95        $plugin = [ $plugin ] unless ref($plugin) eq 'ARRAY'; 
     96        push(@{ $config->{plugins} }, @{ $plugin }); 
     97    } 
    5798} 
    5899