kaldor has asked for the wisdom of the Perl Monks concerning the following question:

Hi all,

I'm using Config::Any to read INI files that don't have ".ini" extension. Config::Any::INI requires Config::Tiny, but when Config::Tiny is NOT installed, the following code doesn't crash (as I would expect) :

use Config::Any; my @plugins = ('Config::Any::INI'); my $cfg = Config::Any->load_files( {files => \@filepaths, force_plugin +s => \@plugins} );

What am I missing here?

Replies are listed 'Best First'.
Re: Config::Any does not complain when Config::Tiny is not installed
by rjt (Curate) on Oct 10, 2019 at 14:14 UTC

    Edit: It's definitely the use of force_plugins. Without that (i.e., with plugins instead), it will indeed error out if Config::Tiny is not present:

    Cannot load test.ini: required support modules are not available. Please install Config::Tiny at config_any.pl line 11.

    The problem is on Config::Any.pm:144:

    # figure out what plugins we're using my @plugins = $force ? map { eval "require $_;"; $_; } @{ $args->{ force_plugins } +} : $class->plugins;

    That map { eval "require $_;" $_ } @... line always returns @{$args->{force_plugins}}, even if one or more modules don't load. I don't know if that is the intended behavior or not (doesn't seem like it, based on my very quick reading of the docs), so it might not hurt to bring it up with the module author(s).

    For now, you can work around the issue by guarding it in your own (calling) code:

    @plugins = grep { eval "require $_" } @plugins;

    ... or raising an error if you want:

    my @missing = grep { !eval "require $_" } @plugins; die "Missing plugin(s): @missing" if @missing;

    Original reply missed the point a bit.

      I had come to the same conclusion, with less technical details though.
      I've open a bug ticket.

      Thank you very much for your help.
      Cheers