aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSergey Poznyakoff <gray@gnu.org.ua>2018-07-10 14:27:07 +0200
committerSergey Poznyakoff <gray@gnu.org.ua>2018-07-10 14:27:07 +0200
commitef4bb8963e1a89da2b62274758361617f5384ce3 (patch)
tree46c7d15cdf08bfd569d7ae6b2910bf361ec37a08
parentdb3dbb29a2ad58ef2f43d3f9d250e7f90aeaf278 (diff)
downloadconfig-parser-ef4bb8963e1a89da2b62274758361617f5384ce3.tar.gz
config-parser-ef4bb8963e1a89da2b62274758361617f5384ce3.tar.bz2
Switch to Config::AST
-rw-r--r--Makefile.PL3
-rw-r--r--lib/Config/Parser.pm12
-rw-r--r--lib/Config/Parser/Ini.pm2
-rw-r--r--t/TestConfig.pm14
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;
2use strict; 2use strict;
3use warnings; 3use warnings;
4use parent 'Config::Tree'; 4use parent 'Config::AST';
5use Carp; 5use Carp;
6use Cwd qw(abs_path); 6use 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;
5use Carp; 5use Carp;
6 6
7use Config::Tree qw(:sort); 7use Config::AST qw(:sort);
8use parent 'Config::Parser::Ini'; 8use parent 'Config::Parser::Ini';
9use Data::Dumper; 9use Data::Dumper;
@@ -65,15 +65,5 @@ sub success {
65sub canonical { 65sub 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

Return to:

Send suggestions and report system problems to the System administrator.