- Fix some bugs in the XML config handling
authorRalf Ertzinger <sun@ryoko.camperquake.de>
Sat, 5 Jan 2008 23:00:30 +0000 (00:00 +0100)
committerRalf Ertzinger <sun@ryoko.camperquake.de>
Sat, 5 Jan 2008 23:00:30 +0000 (00:00 +0100)
videosite.pl
videosite/Base.pm
videosite/DailyMotionGrabber.pm
videosite/MetaCafeGrabber.pm

index 0a8ad3f..7803fa3 100644 (file)
@@ -97,7 +97,7 @@ sub check_for_link {
 sub cmd_save {
 
     open(CONF, '>'.$conffile);
-    print CONF XML::Simple::XMLout($conf, KeepRoot => 1, KeyAttr => ['module', 'key']);
+    print CONF XML::Simple::XMLout($conf, KeepRoot => 1, KeyAttr => {'config' => 'module', 'option' => 'key'});
     close(CONF);
 }
 
@@ -231,7 +231,7 @@ sub init_videosite {
 
     my $p;
 
-    unless(-r $conffile && defined($conf = XML::Simple::XMLin($conffile, ForceArray => ['config', 'option'], KeepRoot => 1, KeyAttr => ['module', 'key']))) {
+    unless(-r $conffile && defined($conf = XML::Simple::XMLin($conffile, ForceArray => ['config', 'option'], KeepRoot => 1, KeyAttr => {'config' => 'module', 'option' => 'key'}))) {
         # No config, start with an empty one
         write_debug(undef, 'No config found, using defaults');
         $conf = { 'videosite' => { 'getter' => '' }};
index 5aa8eae..939e203 100644 (file)
@@ -37,6 +37,8 @@ sub mergeconfig {
     my $c = shift;
     my $o;
 
+    return $self->{'_CONFIG'} unless defined($c);
+
     foreach $o (keys(%{$c->{'option'}})) {
         if (exists($self->{'_CONFIG'}->{'option'}->{$o})) {
             $self->{'_CONFIG'}->{'option'}->{$o}->{'content'} = $c->{'option'}->{$o}->{'content'};
@@ -50,8 +52,7 @@ sub _prepare_parameters {
     my $self = shift;
     my $p;
 
-    $self->{'_CONFIG'} = { 'module' => $self->{'NAME'},
-                           'option' => {}};
+    $self->{'_CONFIG'} = {'option' => {}};
 
     foreach $p (keys(%{$self->{'_PARAMS'}})) {
         $self->{'_CONFIG'}->{'option'}->{$p}->{'content'} = $self->{'_PARAMS'}->{$p}->[0];
index 5dae65d..081b4b4 100644 (file)
@@ -23,6 +23,8 @@ sub new {
 
     bless($self, $class);
 
+    $self->_prepare_parameters();
+
     return $self;
 }
 
index c960ca9..fe68855 100644 (file)
@@ -23,6 +23,8 @@ sub new {
 
     bless($self, $class);
 
+    $self->_prepare_parameters();
+
     return $self;
 }