]> git.proxmox.com Git - pve-common.git/blobdiff - src/PVE/SectionConfig.pm
section config: remove Data::Dumper usage
[pve-common.git] / src / PVE / SectionConfig.pm
index cc03aeaed638db1a4f6c4a736ade97ea90633649..cf87d6f6c3faa5c41f200f5f890cfb29f8304c9b 100644 (file)
@@ -2,12 +2,12 @@ package PVE::SectionConfig;
 
 use strict;
 use warnings;
+
 use Digest::SHA;
+
 use PVE::Exception qw(raise_param_exc);
 use PVE::JSONSchema qw(get_standard_option);
 
-use Data::Dumper;
-
 my $defaultData = {
     options => {},
     plugins => {},
@@ -44,11 +44,11 @@ sub properties {
 
 sub options {
     return {};
-}   
+}
 
 sub plugindata {
     return {};
-}   
+}
 
 sub createSchema {
     my ($class, $skip_type) = @_;
@@ -210,7 +210,7 @@ sub lookup_types {
     my ($class) = @_;
 
     my $pdata = $class->private();
-    
+
     return [ sort keys %{$pdata->{plugins}} ];
 }
 
@@ -234,7 +234,7 @@ sub check_value {
     return $value if $key eq 'type' && $type eq $value;
 
     my $opts = $pdata->{options}->{$type};
-    die "unknown section type '$type'\n" if !$opts; 
+    die "unknown section type '$type'\n" if !$opts;
 
     die "unexpected property '$key'\n" if !defined($opts->{$key});
 
@@ -296,19 +296,22 @@ sub parse_config {
     $raw = '' if !defined($raw);
 
     my $digest = Digest::SHA::sha1_hex($raw);
-    
+
     my $pri = 1;
 
     my $lineno = 0;
     my @lines = split(/\n/, $raw);
     my $nextline = sub {
-       while (my $line = shift @lines) {
+       while (defined(my $line = shift @lines)) {
            $lineno++;
-           return $line if $line !~ /^\s*(?:#|$)/;
+           return $line if ($line !~ /^\s*#/);
        }
     };
 
-    while (my $line = &$nextline()) {
+    while (@lines) {
+       my $line = $nextline->();
+       next if !$line;
+
        my $errprefix = "file $filename line $lineno";
 
        my ($type, $sectionId, $errmsg, $config) = $class->parse_section_header($line);
@@ -331,14 +334,14 @@ sub parse_config {
                }
            }
 
-           while ($line = &$nextline()) {
+           while ($line = $nextline->()) {
                next if $ignore; # skip
 
                $errprefix = "file $filename line $lineno";
 
                if ($line =~ m/^\s+(\S+)(\s+(.*\S))?\s*$/) {
                    my ($k, $v) = ($1, $3);
-   
+
                    eval {
                        die "duplicate attribute\n" if defined($config->{$k});
                        $config->{$k} = $plugin->check_value($type, $k, $v, $sectionId);
@@ -379,10 +382,10 @@ sub check_config {
 
     foreach my $k (keys %$config) {
        my $value = $config->{$k};
-       
+
        die "can't change value of fixed parameter '$k'\n"
-           if !$create && $opts->{$k}->{fixed};
-       
+           if !$create && defined($opts->{$k}) && $opts->{$k}->{fixed};
+
        if (defined($value)) {
            my $tmp = $class->check_value($type, $k, $value, $sectionId, $skipSchemaCheck);
            $settings->{$k} = $class->decode_value($type, $k, $tmp);
@@ -432,13 +435,13 @@ sub write_config {
 
     my $maxpri = 0;
     foreach my $sectionId (keys %$ids) {
-       my $pri = $order->{$sectionId}; 
+       my $pri = $order->{$sectionId};
        $maxpri = $pri if $pri && $pri > $maxpri;
     }
     foreach my $sectionId (keys %$ids) {
        if (!defined ($order->{$sectionId})) {
            $order->{$sectionId} = ++$maxpri;
-       } 
+       }
     }
 
     foreach my $sectionId (sort {$order->{$a} <=> $order->{$b}} keys %$ids) {