The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.

NAME

Config::CmdRC - read rcfile for CLI tools

SYNOPSIS

easy way

    use Config::CmdRC qw/.foorc/;

    # Function `RC` has been exported.
    warn RC->{bar};

specific options

    use Config::CmdRC (
        dir  => ['/path/to/rcdir', '/path/to/other/rcdir'],
        file => ['.foorc', '.barrc'],
    );

DESCRIPTION

Config::CmdRC is the module for automatically reading rcfile in a CLI tool. If you just only use Config::CmdRC with rcfile name, you can get configure parameters as RC function.

By default, Config::CmdRC searches a configuration file in below directories(for UNIX/Linux).

    .
    $ENV{CMDRC_DIR}
    $ENV{HOME}
    /etc

And then, your specified directories will be searched.

If many configuration files are found out, the anterior configuration file will never be lost.

Example:

    use Config::CmdRC (
        dir  => ['/path/to/1', '/path/to/2'],
        file => ['.rc1', '.rc2'],
    );

The parameters of configuration file in '/path/to/1' overwrite parameters of '/path/to/2'. And the parameters of '.rc1' overwrite parameters of '.rc2'.

CUSTOM CONFIG LOADER

In Default, Config::CmdRC uses Config::Simple for reading configuration file.

Of course, you can use original configuration loader like below.

    use Config::Any;

    use Config::CmdRC (
        file   => 'share/custom.yml',
        loader => sub {
            my $path = shift;
            my $cfg = Config::Any->load_files({
                files => [$path],
                use_ext => 1,
            });
            return $cfg->[0]{$path};
        },
    );

EXPORTS

RC

All configuration values are got from RC function. It's exported automatically.

read($rc_file_path)

To read configuration file

CAVEAT

Default search directories for rcfile may be changed in the future.

SEE ALSO

Config::Find

REPOSITORY

Config::CmdRC is hosted on github <http://github.com/bayashi/Config-CmdRC>

Welcome your patches and issues :D

AUTHOR

Dai Okabayashi <bayashi@cpan.org>

LICENSE

This module is free software; you can redistribute it and/or modify it under the same terms as Perl itself. See perlartistic.