--- /dev/null
+package Display::Config;
+
+use Carp;
+use Config::Auto qw/find_file/;
+use FindBin qw/$Bin/;
+use YAML::Syck;
+
+use constant config_file => "Display.yml";
+
+sub new {
+ my $proto = shift;
+ my $class = ref($proto) || $proto;
+
+ my $self = {};
+
+ my $config = Config::Auto::find_file(config_file(), "$Bin/../etc");
+ if (! config || $config eq "") {
+ croak "Failed to find a config file. Looking for ". config_file() . ".";
+ }
+
+ warn "Loading $config\n";
+ my $conf = eval { LoadFile $config };
+ if ($@) {
+ croak "Failed to load config file: $config, error: $@";
+ }
+
+ $self->{_config} = $conf;
+
+ bless ($self, $class);
+ return $self;
+}
+
+1;
use lib "$FindBin::Bin/lib";
+use Display::Config;
use Display::Notifications;
my $full_screen = 1;
$stage->set_size(800, 600);
}
+ my $config = Display::Config->new();
my $notifications = Display::Notifications->new($kernel, $session, $stage);
- my @modules = loadModules($kernel, $session, $stage, $notifications);
+ my @modules = loadModules($kernel, $session, $stage, $config, $notifications);
$stage->show_all();
}
+my @modules;
sub loadModules {
- my ($kernel, $session, $stage, $notifications) = @_;
- my @modules;
+ my ($kernel, $session, $stage, $config, $notifications) = @_;
- for my $module (plugins()) {
- warn "Considering $module\n";
+ my @plugins = plugins();
+ if (defined $config->{_config}{'background'}) {
+ warn "background module is set\n";
+ warn "Considering background: " . join(", ", grep /$config->{_config}{'background'}/, @plugins) . "\n";
+ load_plugin($kernel, $session, $stage, $config, $notifications, grep /$config->{_config}{'background'}/, @plugins );
+ }
+
+ for my $module (@{ $config->{_config}{'enabled'} }) {
+ warn "Considering $module: " . join(", ", grep /$module/, @plugins) . "\n";
+ load_plugin($kernel, $session, $stage, $config, $notifications, grep /$module/, @plugins);
+ }
+}
+
+sub load_plugin {
+ my ($kernel, $session, $stage, $config, $notifications, @plugin) = @_;
+
+ for my $module (@plugin) {
eval "use $module";
if ($@) {
warn "Failed to load plugin: $module ($@)\n";
} else {
- push @modules, $module->new($kernel, $session, $stage, $notifications);
+ push @modules, $module->new($kernel, $session, $stage, $config, $notifications);
}
}
-
- return @modules;
}
sub linear {