Changeset 765

Show
Ignore:
Timestamp:
05/17/06 18:19:18
Author:
miyagawa
Message:
  • Plagger->bootstrap now takes scalar ref containing YAML data, or hash reference of config
  • Plugins are not 'require'd if the module is in memory already
  • Added test suite for Subscription::ConfigINI
Files:

Legend:

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

    r745 r765  
    4141    if (-e $opt{config} && -r _) { 
    4242        $config = YAML::LoadFile($opt{config}); 
    43         $self->load_include($config); 
    44         $self->{conf} = $config->{global}; 
    45         $self->{conf}->{log} ||= { level => 'debug' }; 
    4643        $self->{config_path} = $opt{config}; 
     44    } elsif (ref($opt{config}) && ref($opt{config}) eq 'SCALAR') { 
     45        $config = YAML::Load(${$opt{config}}); 
     46    } elsif (ref($opt{config}) && ref($opt{config}) eq 'HASH') { 
     47        $config = $opt{config}; 
    4748    } else { 
    4849        croak "Plagger->bootstrap: $opt{config}: $!"; 
    4950    } 
     51 
     52    $self->load_include($config); 
     53    $self->{conf} = $config->{global}; 
     54    $self->{conf}->{log} ||= { level => 'debug' }; 
    5055 
    5156    local *Plagger::context = sub { $self }; 
     
    6570sub rewrite_config { 
    6671    my $self = shift; 
     72 
     73    unless ($self->{config_path}) { 
     74        $self->log(warn => "config is not loaded from file. Ignoring rewrite tasks."); 
     75        return; 
     76    } 
    6777 
    6878    open my $fh, $self->{config_path} or $self->error("$self->{config_path}: $!"); 
     
    234244    $module = "Plagger::Plugin::$module"; 
    235245 
    236     if (my $path = $self->plugins_path->{$module}) { 
    237         eval { require $path } or die $@
     246    if ($module->isa('Plagger::Plugin')) { 
     247        $self->log(debug => "$module is loaded elsewhere ... maybe .t script?")
    238248    } else { 
    239         $module->require or die $@; 
     249        if (my $path = $self->plugins_path->{$module}) { 
     250            eval { require $path } or die $@; 
     251        } else { 
     252            $module->require or die $@; 
     253        } 
    240254    } 
    241255