diff options
author | Sergey Poznyakoff <gray@gnu.org.ua> | 2018-07-10 14:27:07 +0200 |
---|---|---|
committer | Sergey Poznyakoff <gray@gnu.org.ua> | 2018-07-10 14:27:07 +0200 |
commit | ef4bb8963e1a89da2b62274758361617f5384ce3 (patch) | |
tree | 46c7d15cdf08bfd569d7ae6b2910bf361ec37a08 | |
parent | db3dbb29a2ad58ef2f43d3f9d250e7f90aeaf278 (diff) | |
download | config-parser-ef4bb8963e1a89da2b62274758361617f5384ce3.tar.gz config-parser-ef4bb8963e1a89da2b62274758361617f5384ce3.tar.bz2 |
Switch to Config::AST
-rw-r--r-- | Makefile.PL | 3 | ||||
-rw-r--r-- | lib/Config/Parser.pm | 12 | ||||
-rw-r--r-- | lib/Config/Parser/Ini.pm | 2 | ||||
-rw-r--r-- | t/TestConfig.pm | 14 |
4 files changed, 11 insertions, 20 deletions
diff --git a/Makefile.PL b/Makefile.PL index bc0ba75..cee8413 100644 --- a/Makefile.PL +++ b/Makefile.PL @@ -13,13 +13,14 @@ WriteMakefile(NAME => 'Config::Parser', PREREQ_PM => { 'Carp' => 0, 'Text::ParseWords' => 0, 'Class::Inspector' => 0, 'Data::Dumper' => '2.135_06', 'File::Temp' => '0.22', - 'Text::Locus' => '1.01' + 'Text::Locus' => '1.01', + 'Config::AST' => 0 }, META_MERGE => { 'meta-spec' => { version => 2 }, resources => { repository => { type => 'git', diff --git a/lib/Config/Parser.pm b/lib/Config/Parser.pm index 93b23fc..ee5055b 100644 --- a/lib/Config/Parser.pm +++ b/lib/Config/Parser.pm @@ -1,10 +1,10 @@ package Config::Parser; use strict; use warnings; -use parent 'Config::Tree'; +use parent 'Config::AST'; use Carp; use Cwd qw(abs_path); use Text::ParseWords; use Class::Inspector; our $VERSION = "1.00"; @@ -20,24 +20,24 @@ sub new { if (my $v = delete $_{$k}) { push @parseargs, ($k, $v); } } } - unless ($_{parameters}) { + unless ($_{lexicon}) { my $subs = Class::Inspector->subclasses(__PACKAGE__); if ($subs) { - $_{parameters} = {}; + $_{lexicon} = {}; foreach my $c (@$subs) { # print "LOADING FROM $c\n"; if (my $s = loadsynt($c)) { - $_{parameters} = { %{$_{parameters}}, %$s }; + $_{lexicon} = { %{$_{lexicon}}, %$s }; } last if $c eq $class; } - delete $_{parameters} unless keys %{$_{parameters}}; + delete $_{lexicon} unless keys %{$_{lexicon}}; } } my $self = $class->SUPER::new(%_); if (@parseargs) { @@ -68,13 +68,13 @@ sub loadsynt { my ($class) = @_; if (my ($file, $line, $data) = findsynt($class)) { open(my $fh, '<', \$data); my $d = $class->new(filename => $file, fh => $fh, line => $line, - parameters => { '*' => '*' }) + lexicon => { '*' => '*' }) or croak "Failed to parse template at $file:$line"; close $fh; $d->as_hash(sub { my ($what, $name, $val) = @_; $name = '*' if $name eq 'ANY'; if ($what eq 'section') { diff --git a/lib/Config/Parser/Ini.pm b/lib/Config/Parser/Ini.pm index 3b39a16..0ea632c 100644 --- a/lib/Config/Parser/Ini.pm +++ b/lib/Config/Parser/Ini.pm @@ -59,13 +59,13 @@ sub _readconfig { @path = parse_line('\s+', 0, $1); if (@path == 1 && $path[0] eq 'include') { $include = 1; } else { $include = 0; $self->add_node(\@path, - new Config::Tree::Node::Section(locus => $locus)); + new Config::AST::Node::Section(locus => $locus)); } } elsif (/([\w_-]+)\s*=\s*(.*)/) { my ($k, $v) = ($1, $2); $k = lc($k) if $self->{_ci}; #FIXME:private member if ($include) { diff --git a/t/TestConfig.pm b/t/TestConfig.pm index 886e66b..bd4f3f5 100644 --- a/t/TestConfig.pm +++ b/t/TestConfig.pm @@ -1,13 +1,13 @@ package TestConfig; use strict; use warnings; use Carp; -use Config::Tree qw(:sort); +use Config::AST qw(:sort); use parent 'Config::Parser::Ini'; use Data::Dumper; use File::Temp; =head1 CONSTRUCTOR @@ -61,23 +61,13 @@ sub success { my ($self) = @_; return $self->{_status}; } sub canonical { my $self = shift; - local %_ = @_; - carp "unknown parameters: " . join(', ', keys(%_)) if (keys(%_)); - return join $_{delim} // " ", map { - join('.', @{$_->[0]}) - . "=" - . Data::Dumper->new([$_->[1]->value]) - ->Useqq(1) - ->Terse(1) - ->Indent(0) - ->Dump - } $self->flatten(sort => SORT_PATH); + return $self->SUPER::canonical(delim => ' '); } sub expected_error { my ($self, $msg) = @_; if (exists($self->{_expected_errors})) { |