aboutsummaryrefslogtreecommitdiff
path: root/lib/Config/Parser.pm
diff options
context:
space:
mode:
Diffstat (limited to 'lib/Config/Parser.pm')
-rw-r--r--lib/Config/Parser.pm61
1 files changed, 27 insertions, 34 deletions
diff --git a/lib/Config/Parser.pm b/lib/Config/Parser.pm
index fed0100..0f0a1f0 100644
--- a/lib/Config/Parser.pm
+++ b/lib/Config/Parser.pm
@@ -23,25 +23,25 @@ sub new {
}
}
}
+
+ my $self = $class->SUPER::new(%_);
- unless ($_{lexicon}) {
+ if (my $lex = delete $_{lexicon}) {
+ $self->lexicon($lex);
+ } else {
+ $self->lexicon({ '*' => '*' });
my $subs = Class::Inspector->subclasses(__PACKAGE__);
if ($subs) {
- $_{lexicon} = {};
foreach my $c (@$subs) {
-# print "LOADING FROM $c\n";
- if (my $s = loadsynt($c)) {
- $_{lexicon} = { %{$_{lexicon}}, %$s };
- $loaded++;
+ if (my ($file, $line, $data) = $c->findsynt) {
+ $self->loadsynt($file, $line, $data);
}
last if $c eq $class;
}
- delete $_{lexicon} unless keys %{$_{lexicon}};
}
}
- my $self = $class->SUPER::new(%_);
- $self->init if $loaded;
+ $self->init;
if (@parseargs) {
$self->parse(@parseargs);
$self->commit or croak "configuration failed";
@@ -50,19 +50,13 @@ sub new {
return $self;
}
-sub init {
- my $self = shift;
- $self->{_inited} = 1;
-}
-
-sub inited { shift->{_inited} };
+sub init {}
+sub mangle {}
sub commit {
my $self = shift;
my $res = $self->SUPER::commit;
- if ($res && $self->inited && $self->can('mangle')) {
- $self->mangle;
- }
+ $self->mangle if $res;
return $res;
}
@@ -83,18 +77,18 @@ sub findsynt {
}
sub loadsynt {
- my ($class) = @_;
- if (my ($file, $line, $data) = findsynt($class)) {
- open(my $fh, '<', \$data)
- or croak "can't open filehandle for data string";
- my $d = $class->new(filename => $file,
- fh => $fh,
- line => $line,
- lexicon => { '*' => '*' })
- or croak "Failed to parse template at $file:$line";
- close $fh;
- $d->as_hash(sub {
- my ($what, $name, $val) = @_;
+ my ($self, $file, $line, $data) = @_;
+ open(my $fh, '<', \$data)
+ or croak "can't open filehandle for data string";
+ $self->parse($file,
+ fh => $fh,
+ line => $line)
+ or croak "Failed to parse template at $file:$line";
+ close $fh;
+ $self->lexicon({
+ %{$self->lexicon // {}},
+ %{$self->as_hash(sub {
+ my ($what, $name, $val) = @_;
$name = '*' if $name eq 'ANY';
if ($what eq 'section') {
$val->{section} = {};
@@ -106,7 +100,7 @@ sub loadsynt {
my @words = parse_line('\s+', 0, $val);
my $ret = {};
$val = shift @words;
-
+
if ($val eq 'STRING') {
# nothing
} elsif ($val eq 'NUMBER') {
@@ -128,13 +122,12 @@ sub loadsynt {
if ($ret->{array}) {
$ret->{default} = [@words];
} else {
- $ret->{default} = join(' ', @words);
+ $ret->{default} = join(' ', @words);
}
}
($name, $ret);
}
- })->{section};
- }
+ })->{section}}});
}
1;

Return to:

Send suggestions and report system problems to the System administrator.