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::IniFiles::Check::Health - check ini-files for needed values

VERSION

Version 0.09

SYNOPSIS

    use Config::IniFiles::Check::Health;

    # see new()

DESCRIPTION

Config-IniFiles-Check-Health

Working with Config::IniFiles needs to check the ini-files for

* checking for existing, needed values in the sections * double-vars in a single section * do all needed sections exist

SYNOPSIS

    my $ini_fn = 'utf8convertbin.ini';
    my $ini_obj = Config::IniFiles->new( -file => $ini_fn );

    Log::Log4perl::ConfigByInifile->new(
        { ini_obj => $ini_obj, }
    );
    my $logger = get_logger();

    my $ini_health_checker_obj = Config::IniFiles::Check::Health->new({
        logger => $logger,
        ini_obj => $ini_obj
    });

    # Work to be done:
    $ini_health_checker_obj->check_inifile_for_values({
        values_must_exists => [
            { section => 'inifiles', varname => 'findus_ini_latin1_dn' },
            { section => 'inifiles', varname => 'findus_ini_utf8_dn' },
        ]
    });

    $ini_health_checker_obj->check_for_sections({
        sections_must_exist => [ qw(log4perl inifiles) ]
    });

    $ini_health_checker_obj->check_inifile_for_values({
        values_must_exists => [
            { section => 'inifiles', varname => 'findus_ini_latin1_dn' },
            { section => 'inifiles', varname => 'findus_ini_utf8_dn' },
        ]
    });

FUNCTIONS

new

    my $ini_fn = 'utf8convertbin.ini';
    my $ini_obj = Config::IniFiles->new( -file => $ini_fn );

    my $ini_health_checker_obj = Config::IniFiles::Check::Health->new({
        # Log4perl-definition is a section in the inifile
        # so: firstly undef
        logger => undef,
        ini_obj => $ini_obj
        # optional, with default value
        errors_are_fatal => 1
    });
    $ini_health_checker_obj->check_for_sections({
        sections_must_exist => [ qw(log4perl inifiles) ]
    });

    Log::Log4perl::ConfigByInifile->new(
        { ini_obj => $ini_obj, }
    );
    my $logger = get_logger();

    # Tell about our 
    $ini_health_checker_obj->logger($logger);

    $ini_health_checker_obj->check_inifile_for_values({
        values_must_exists => [
            { section => 'inifiles', varname => 'findus_ini_latin1_dn' },
            { section => 'inifiles', varname => 'findus_ini_utf8_dn' },
        ]
    });

logger

You can set logger to a real Perl-Log-Objekt or to undef. This is to starte the object and make some tests without having a log-object in the very beginning because the log-object is built with information from the ini-file.

    $obj->new({ logger => undef, ...})

    # Later...
    $obj->logger( Log::Log4perl::get_logger('Bla::Foo') )

errors_are_fatal

You can switch behaviour of the following tests:

    $obj->errors_are_fatal(1); # default
    # There should be errors, but not die
    $obj->errors_are_fatal(0);
    $obj->check_for_duplicate_vars_in_one_section('berlin');

check_for_duplicate_vars_in_one_section

    $obj->check_for_duplicate_vars_in_all_sections();

check_for_duplicate_vars_in_one_section

Try to avoid double vars entries like this:

    ; my.ini
    [berlin]
    dogs=20
    dogs=30
    cats=10

Usage:

    $obj->check_for_duplicate_vars_in_one_section({ section => 'berlin' });

check_for_sections

    $ini_health_checker_obj->check_for_sections({
        sections_must_exist => [ qw(berlin vienna) ]
    });

check_inifile_for_values

    $ini_health_checker_obj->check_inifiles_for_values({
        values_must_exists => [
            { section => 'bla', varname => 'nr_of_cars'},
            { section => 'bla', varname => 'nr_of_dogs'},
        ],
    });

_log_error

    $self->_log_error("Bad thing");

_log_error

    if ($self->errors_are_fatal && $nr_of_errors > 0) {
        $log_msg = sprintf 'Too many errors in check_inifile_for_sections';
        $self->_log_fatal($log_msg);
    }

AUTHOR

Richard Lippmann, <horshack at cpan.org>

BUGS

Please report any bugs or feature requests to bug-config-inifiles-check-health at rt.cpan.org, or through the web interface at https://rt.cpan.org/NoAuth/ReportBug.html?Queue=Config-IniFiles-Check-Health. I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.

SUPPORT

You can find documentation for this module with the perldoc command.

    perldoc Config::IniFiles::Check::Health

You can also look for information at:

ACKNOWLEDGEMENTS

LICENSE AND COPYRIGHT

This software is Copyright (c) 2024 by Richard Lippmann.

This is free software, licensed under:

  The Artistic License 2.0 (GPL Compatible)