[Catalyst] Hair-pulling over YAML config

Joel Bernstein joel at fysh.org
Mon Jan 29 17:20:32 GMT 2007


On Mon, Jan 29, 2007 at 10:31:13AM -0600, Jonathan Rockway wrote:
> Carl Vincent wrote:
> > I've patched my Config::Any (attached below) so it throws a warning. Not
> > sure if this would cause problems if it was included in the distributed
> > module...
> 
> This is something I've been worried about for a while.  Config::Any
> tries to load every config file with every "backend", so printing
> warnings is going to lead to a lot of spurious garbage.
> 
> Perhaps making ConfigLoader louder would help?  If no config is loaded
> (but ConfigLoader is loaded), then perhaps we need to
> 
>   [warn] Config file found but failed to load.  Errors
>   [warn] YAML_OMG_YOU_FORGOT_SOMETHING (Line 42, Column 32)
>             etc.
>   [warn] XML::Parser error: no <?xml ?> declaration
>   [warn] JSON ...
> 
> As you can see it's kind of verbose that way.  What do other people think?

I'm looking into this. You're wrong about Config::Any trying to load
files with every backend, though. Config::Any *can* do that, but
C::P::ConfigLoader doesn't use that:
sub setup {
    my $c     = shift;
    my @files = $c->find_files;
    my $cfg   = Config::Any->load_files( {
        files   => \@files, 
        filter  => \&_fix_syntax,
        use_ext => 1
    } );

that use_ext => 1 means "use the file extension to determine which
plugins to offer it to", so we can be fairly sure *providing that the
user is correctly naming their config files* that anything we offer to a
plugin ought to be the correct format.

On the one hand, users creating broken YAML (or whatever) files is out
of our scope. On the other, we mustn't make it any more difficult for
them to see the errors reported on their files than it would be if they
used YAML.pm directly.

I think the difficulty here is that Config::Any::_load has the potential
if running without use_ext=>1 to generate a lot of spurious warnings
caused by all the plugins to which a given config file is offered, but
which can't parse the file. So any patch would presumably only report
warnings if use_ext=>1. But that still doesn't seem ideal. Suggestions?

/joel



More information about the Catalyst mailing list