Skip Menu |

This queue is for tickets about the Config-General CPAN distribution.

Report information
The Basics
Id: 21109
Status: resolved
Priority: 5/
Queue: Config-General

People
Owner: tlinden [...] cpan.org
Requestors: rataxis [...] cpan.org
Cc:
AdminCc:

Bug Information
Severity: Wishlist
Broken in: 2.31
Fixed in: (no value)



Subject: Config::General parses totally invalid data happily into nonsense
I'm working on a module called Config::Any, designed to allow an app to have configuration loaded from different kinds of config file, including Config::General. My understanding is that the following file is /not/ valid Config::General: $ cat conf/conf.pl { name => 'TestApp', 'Controller::Foo' => { foo => 'bar' }, 'Model::Baz' => { qux => 'xyzzy' } } Manifestly, it's Perl source, and it looks nothing like Apache-style config. Not a <Tag>...</Tag> in sight. It looks to me that Config::General makes an assumption that anything it's handed ought to be valid for it to parse. It happens to be able to parse the file above, and outputs a shocking mess: $ perl -MConfig::General -MData::Dump -le 'my $cfg = { Config::General->new("conf/conf.pl")->getall }; print Data::Dump::dump($cfg)' { "'Controller::Foo'" => "> {", "'Model::Baz'" => "> {", foo => "> 'bar'", name => "> 'TestApp',", qux => "> 'xyzzy'", "{" => "", "}" => ["", ""], "}," => "", } Is this by design? I think there should be some better heuristic to detect whether the input file is indeed valid - the output above should surely not occur? Am I missing something? I realise you may be short of time to work on this. I'm happy to try to work with you to develop a patch against Config::General, if you like. Do you agree that C::G should be more strict about what input it accepts, though? Obviously the user is at fault if they hand C::G Perl code to parse, but it would make stuff a lot easier if C::G were to validate its input more carefully.
Sorry for the late reply - RT didn't notify me of new tickets. Well - for now this is by design, because the module is not primarily designed for apache-style configs, but for simple config files, for which it will be used in most cases, eg: [..] dir = /blah user = root [..] Of course, it could do validation on its input, for instance if input is not xml, perl, ini-style, yaml or whatever. In fact I'm not sure how to fix this without breaking anything. If you've got an idea - get back to me.
I wrote an extra module for this: Config::General::Validate. Try it at: http://search.cpan.org/~tlinden/Config-General-Validate-1.00/ (note: I uploaded it some minutes ago, it will take a while until its visible!)