Skip Menu |

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

Report information
The Basics
Id: 11622
Status: resolved
Priority: 0/
Queue: Config-Auto

Owner: Nobody in particular
Requestors: william [...]

Bug Information
Severity: Important
Broken in: 0.11
Fixed in: (no value)


Subject: Compile errors do not propagate
Download (untitled) / with headers
text/plain 1.1k
Hi Jos, An issue that I've discovered while using Config::Auto with taintmode is that the do() function returns undef if the file being compiled generates an error. This is also the case for normal perl files that fail to compile due to syntax errors or other problems. In both cases, Config::Auto simply returns an undef value rather than die'ing with an error. I've modified the eval_perl function again to include tests for read and compile errors. These simple tests are based on the example code in `perldoc -f do` (perl 5.8.4) and would have saved me a bit of time yesterday so I hope that you will include them. My preference would be that all of these tests should die if they fail but emitting a warning for the last two would suffice (compile errors should always throw a die). In addition to the error checking patch, I've made some modifications to the POD which includes a list of the formats (so I don't have to look in the code or tell others to check the code to see what formats are supported), a trouble-shooting section, and a revision to the description of the Untaint setting to provide a more accurate explanation of what is being untainted. Thanks, William
text/x-diff 2.3k
--- 2004-11-10 05:36:26.000000000 -0500 +++ /home/william/work/gaitways/web/Partners/perl5/Config/ 2005-02-22 13:06:27.000000000 -0500 @@ -149,7 +150,15 @@ return undef; } -sub eval_perl { do $_[0]; } +sub eval_perl { + my $file = shift; + ($file) = $file =~ m/^(.*)$/s if $Untaint; + my $cfg = do $file; + die "Config::Auto couldn't parse $file: $@" if $@; + die "Config::Auto couldn't do $file: $!" unless defined $cfg; + die "Config::Auto couldn't run $file" unless $cfg; + return $cfg; +} sub parse_xml { return XMLin(shift); } sub parse_ini { tie my %ini, 'Config::IniFiles', (-file=>$_[0]); return \%ini; } sub return_list { open my $fh, shift or die $!; return [<$fh>]; } @@ -324,6 +333,12 @@ If you don't want it ever to detect and execute config files which are made up of Perl code, set C<$Config::Auto::DisablePerl = 1>. +When using the perl format, your configuration file will be eval'd using +do(file). This will cause taint errors if the filename is not untainted. To +avoid these warnings, set C<$Config::Auto::Untaint = 1>. This setting will not +untaint the data in your configuration file and should only be used if you +trust the source of the filename. + Then the file is parsed and a data structure is returned. Since we're working magic, we have to do the best we can under the circumstances - "You rush a miracle man, you get rotten miracles." (Miracle Max) So @@ -390,6 +405,43 @@ C<format>, which forces C<Config::Auto> to interpret the contents of the configuration file in the given format without trying to guess. +=head2 Formats + +C<Config::Auto> recognizes the following formats: + +=over 4 + +=item * Perl => perl code + +=item * colon => colon separated (e.g., key:value) + +=item * space => space separated (e.g., key value) + +=item * equal => equal separated (e.g., key=value) + +=item * bind => bind style (not available) + +=item * irssi => irssi style (not available) + +=item * xml => xml (via XML::Simple) + +=item * ini => .ini format (via Config::IniFiles) + +=item * list => list (e.g., ??) + +=back + + +=head1 TROUBLESHOOTING + +=over 4 + +=item When using a Perl config file, the configuration is borked + +Give C<Config::Auto> more hints (e.g., add #!/usr/bin/perl to beginning of +file) or indicate the format in the parse() command. + + =head1 TODO BIND9 and irssi file format parsers currently don't exist. It would be
Download (untitled) / with headers
text/plain 248b
[guest - Tue Feb 22 13:15:11 2005]: Show quoted text
> In addition to the error checking patch, I've made some modifications > to the POD which includes a list of the formats
Thanks, applied @11984 For extra browniepoints, test patches are always welcome :)

This service is sponsored and maintained by Best Practical Solutions and runs on infrastructure.

Please report any issues with to