Changeset 1327
- Timestamp:
- 08/15/06 20:01:51
- Files:
-
- trunk/plagger/bin/plagger-ircbot (modified) (2 diffs)
- trunk/plagger/lib/Plagger.pm (modified) (4 diffs)
- trunk/plagger/lib/Plagger/ConfigLoader.pm (added)
- trunk/plagger/t/core/include.t (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/plagger/bin/plagger-ircbot
r1325 r1327 3 3 use strict; 4 4 5 use Plagger;6 5 use FindBin; 6 use lib "$FindBin::Bin/../lib"; 7 7 8 use Getopt::Long; 8 9 use List::Util qw(first); 9 10 use YAML; 11 12 use Plagger::ConfigLoader; 10 13 11 14 use POE qw( … … 25 28 msg "loading configuration $path"; 26 29 27 my $config_yaml = YAML::LoadFile($path); 30 my $loader = Plagger::ConfigLoader->new; 31 my $base_config = $loader->load($path); 28 32 29 # temp hack to allow include/recipes 30 Plagger::load_include(undef, $config_yaml);31 Plagger::load_recipes(undef, $config_yaml); 32 my $plugin = first { $_->{module} eq 'Notify::IRC' } @{ $ config_yaml->{plugins} }33 $loader->load_include($base_config); 34 $loader->load_recipes($base_config); 35 36 my $plugin = first { $_->{module} eq 'Notify::IRC' } @{ $base_config->{plugins} } 33 37 or die "Can't find Notify::IRC config in $path"; 34 38 trunk/plagger/lib/Plagger.pm
r1267 r1327 19 19 use Plagger::Cache; 20 20 use Plagger::CacheProxy; 21 use Plagger::ConfigLoader; 21 22 use Plagger::Date; 22 23 use Plagger::Entry; … … 40 41 }, $class; 41 42 42 my $config; 43 if (-e $opt{config} && -r _) { 44 $config = YAML::LoadFile($opt{config}); 45 $self->{config_path} = $opt{config}; 46 } elsif (ref($opt{config}) && ref($opt{config}) eq 'SCALAR') { 47 $config = YAML::Load(${$opt{config}}); 48 } elsif (ref($opt{config}) && ref($opt{config}) eq 'HASH') { 49 $config = Storable::dclone($opt{config}); 50 } else { 51 croak "Plagger->bootstrap: $opt{config}: $!"; 52 } 53 54 $self->load_include($config); 43 my $loader = Plagger::ConfigLoader->new; 44 my $config = $loader->load($opt{config}); 45 46 $loader->load_include($config); 55 47 $self->{conf} = $config->{global}; 56 48 $self->{conf}->{log} ||= { level => 'debug' }; … … 63 55 local *Plagger::context = sub { $self }; 64 56 65 $ self->load_recipes($config);57 $loader->load_recipes($config); 66 58 $self->load_cache($opt{config}); 67 59 $self->load_plugins(@{ $config->{plugins} || [] }); … … 109 101 110 102 $self->log(info => "Rewrote $count password(s) and saved to $self->{config_path}"); 111 }112 }113 114 sub load_include {115 my($self, $config) = @_;116 117 return unless $config->{include};118 for (@{ $config->{include} }) {119 my $include = YAML::LoadFile($_);120 121 for my $key (keys %{ $include }) {122 my $add = $include->{$key};123 unless ($config->{$key}) {124 $config->{$key} = $add;125 next;126 }127 if (ref($config->{$key}) eq 'HASH') {128 next unless ref($add) eq 'HASH';129 for (keys %{ $include->{$key} }) {130 $config->{$key}->{$_} = $include->{$key}->{$_};131 }132 } elsif (ref($include->{$key}) eq 'ARRAY') {133 $add = [ $add ] unless ref($add) eq 'ARRAY';134 push(@{ $config->{$key} }, @{ $include->{$key} });135 } elsif ($add) {136 $config->{$key} = $add;137 }138 }139 }140 }141 142 sub load_recipes {143 my($self, $config) = @_;144 145 for (@{ $config->{recipes} }) {146 $self->error("no such recipe to $_") unless $config->{define_recipes}->{$_};147 my $plugin = $config->{define_recipes}->{$_};148 $plugin = [ $plugin ] unless ref($plugin) eq 'ARRAY';149 push(@{ $config->{plugins} }, @{ $plugin });150 103 } 151 104 } trunk/plagger/t/core/include.t
r1326 r1327 6 6 run { 7 7 my $block = shift; 8 my $config = YAML::Load($block->input);9 8 10 my $context = bless {}, 'Plagger'; 11 $context->load_include($config); 12 $context->load_recipes($config); 9 my $loader = Plagger::ConfigLoader->new; 10 my $config = $loader->load(\$block->input); 11 12 $loader->load_include($config); 13 $loader->load_recipes($config); 13 14 14 15 # no need to compare these things
