use strict; use Data::Dumper; my (undef, @conf) = split ($/, " " ); my $conf = MyConfig::General->new(\@conf); print Dumper {$conf->getall}; package MyConfig::General; use base 'Config::General'; sub _open { my ( $this, $arrayref ) = @_; my ( @content, $c_comment, $longline, $hier, $hierend, @hierdoc ); local $_; for (@$arrayref) { chomp; if ( !$hierend ) { s/(?{content} }, $hier; @hierdoc = (); undef $hier; undef $hierend; } elsif (/^\s*\/\*/) { if (/\*\/\s*$/) { $c_comment = 0; } else { $c_comment = 1; } } elsif (/\*\//) { if ( !$c_comment ) { warn "invalid syntax: found end of C-comment without previous start!\n"; } $c_comment = 0; } elsif (/\\$/) { chop; s/^\s*//; $longline .= $_ if ( !$c_comment ); } else { if ($longline) { s/^\s*//; $longline .= $_ if ( !$c_comment ); push @{ $this->{content} }, $longline; undef $longline; } elsif ($hier) { push @hierdoc, $_; } else { if ( !$c_comment ) { my $incl_file; if ( /^\s*<>\s*$/i || ( /^\s*include (.+?)\s*$/i && $this->{UseApacheInclude} ) ) { $incl_file = $1; if ( $this->{IncludeRelative} && $this->{configpath} && $incl_file !~ /^\// ) { $this->_open( $this->{configpath} . "/" . $incl_file ); } else { $this->_open($incl_file); } } else { push @{ $this->{content} }, $_; } } } } } return 1; } #### my @errors; my %valid = ( url => { required => 1, regex => qr{^http://[\w./]}, }, maxdepth => { required => 1, regex => qr{^\d+$}, maximum => 10, }, ); my $conf = MyConfig::General->new(\@conf); my %conf = $conf->getall; my %tmpl = %{$conf{template}}; for (keys %valid) { my $v = $valid{$_} or next; if ($v->{required}) { unless ($tmpl{$_} !~ /^\s*$/) { push @errors, "$_ is missing" } } if ($v->{regex}) { unless ($tmpl{$_} =~ /$v->{regex}/) { push @errors, "$_ has invalid format: $tmpl{$_}" } } if ($v->{maximum}) { unless ($tmpl{$_} <= $v->{maximum}) { push @errors, "$_ is too large: $tmpl{$_}" } } } print Dumper \@errors;