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 | |||
@@ -17,5 +17,6 @@ WriteMakefile(NAME => 'Config::Parser', | |||
17 | 'Data::Dumper' => '2.135_06', | 17 | 'Data::Dumper' => '2.135_06', |
18 | 'File::Temp' => '0.22', | 18 | 'File::Temp' => '0.22', |
19 | 'Text::Locus' => '1.01' | 19 | 'Text::Locus' => '1.01', |
20 | 'Config::AST' => 0 | ||
20 | }, | 21 | }, |
21 | META_MERGE => { | 22 | META_MERGE => { |
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 | |||
@@ -2,5 +2,5 @@ package Config::Parser; | |||
2 | use strict; | 2 | use strict; |
3 | use warnings; | 3 | use warnings; |
4 | use parent 'Config::Tree'; | 4 | use parent 'Config::AST'; |
5 | use Carp; | 5 | use Carp; |
6 | use Cwd qw(abs_path); | 6 | use Cwd qw(abs_path); |
@@ -24,16 +24,16 @@ sub new { | |||
24 | } | 24 | } |
25 | 25 | ||
26 | unless ($_{parameters}) { | 26 | unless ($_{lexicon}) { |
27 | my $subs = Class::Inspector->subclasses(__PACKAGE__); | 27 | my $subs = Class::Inspector->subclasses(__PACKAGE__); |
28 | if ($subs) { | 28 | if ($subs) { |
29 | $_{parameters} = {}; | 29 | $_{lexicon} = {}; |
30 | foreach my $c (@$subs) { | 30 | foreach my $c (@$subs) { |
31 | # print "LOADING FROM $c\n"; | 31 | # print "LOADING FROM $c\n"; |
32 | if (my $s = loadsynt($c)) { | 32 | if (my $s = loadsynt($c)) { |
33 | $_{parameters} = { %{$_{parameters}}, %$s }; | 33 | $_{lexicon} = { %{$_{lexicon}}, %$s }; |
34 | } | 34 | } |
35 | last if $c eq $class; | 35 | last if $c eq $class; |
36 | } | 36 | } |
37 | delete $_{parameters} unless keys %{$_{parameters}}; | 37 | delete $_{lexicon} unless keys %{$_{lexicon}}; |
38 | } | 38 | } |
39 | } | 39 | } |
@@ -72,5 +72,5 @@ sub loadsynt { | |||
72 | fh => $fh, | 72 | fh => $fh, |
73 | line => $line, | 73 | line => $line, |
74 | parameters => { '*' => '*' }) | 74 | lexicon => { '*' => '*' }) |
75 | or croak "Failed to parse template at $file:$line"; | 75 | or croak "Failed to parse template at $file:$line"; |
76 | close $fh; | 76 | close $fh; |
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 | |||
@@ -63,5 +63,5 @@ sub _readconfig { | |||
63 | $include = 0; | 63 | $include = 0; |
64 | $self->add_node(\@path, | 64 | $self->add_node(\@path, |
65 | new Config::Tree::Node::Section(locus => $locus)); | 65 | new Config::AST::Node::Section(locus => $locus)); |
66 | } | 66 | } |
67 | } elsif (/([\w_-]+)\s*=\s*(.*)/) { | 67 | } elsif (/([\w_-]+)\s*=\s*(.*)/) { |
diff --git a/t/TestConfig.pm b/t/TestConfig.pm index 886e66b..bd4f3f5 100644 --- a/t/TestConfig.pm +++ b/t/TestConfig.pm | |||
@@ -5,5 +5,5 @@ use warnings; | |||
5 | use Carp; | 5 | use Carp; |
6 | 6 | ||
7 | use Config::Tree qw(:sort); | 7 | use Config::AST qw(:sort); |
8 | use parent 'Config::Parser::Ini'; | 8 | use parent 'Config::Parser::Ini'; |
9 | use Data::Dumper; | 9 | use Data::Dumper; |
@@ -65,15 +65,5 @@ sub success { | |||
65 | sub canonical { | 65 | sub canonical { |
66 | my $self = shift; | 66 | my $self = shift; |
67 | local %_ = @_; | 67 | return $self->SUPER::canonical(delim => ' '); |
68 | carp "unknown parameters: " . join(', ', keys(%_)) if (keys(%_)); | ||
69 | return join $_{delim} // " ", map { | ||
70 | join('.', @{$_->[0]}) | ||
71 | . "=" | ||
72 | . Data::Dumper->new([$_->[1]->value]) | ||
73 | ->Useqq(1) | ||
74 | ->Terse(1) | ||
75 | ->Indent(0) | ||
76 | ->Dump | ||
77 | } $self->flatten(sort => SORT_PATH); | ||
78 | } | 68 | } |
79 | 69 | ||