NAME

MooseX::ConfigCascade::Util - utility module for MooseX::ConfigCascade

SYNOPSIS

    use MooseX::ConfigCascade::Util;

    MooseX::ConfigCascade::Util->path(      # set the path to the config file

        '/path/to/config.json' 

    );  


    MooseX::ConfigCascade::Util->conf(      # set the config hash directly

        \%conf 

    ); 


    MooseX::ConfigCascade::Util->parser(    # set the sub that parses the 
                                            # config file
        $subroutine_reference

    );

DESCRIPTION

This is module is the workhorse of MooseX::ConfigCascade. See the MooseX::ConfigCascade documentation for a general overview of how to implement MooseX::ConfigCascade in your project.

METHODS

MooseX provides an attribute conf which stores a hash of config directives, and 2 attributes path and parser which control how conf is loaded

conf

This is a hashref containing config information. See the documentation for MooseX::ConfigCascade to learn how this should be structured. It can be set directly

    MooseX::ConfigCascade::Util->conf( \%conf );

Alternatively it is set indirectly when 'path' is changed

path

Call this to set the path to your config file. For more information about the format of your config file, see the documentation for MooseX::ConfigCascade.

    MooseX::ConfigCascade::Util->path( '/path/to/my_config.json' );

When path is changed it reads the specified file and overwrites conf with the new values. Any new objects created after that will get the new values.

parser

This is the subroutine responsible for converting the file specified in path to a hashref. Setting this to a new value means you can use MooseX::ConfigCascade with a config file of arbitrary format. But look at the expected format of this sub below, and use with caution:

Your parser subroutine should collect path from the input arguments, do whatever is necessary to convert the file, and finally output the hashref which will be stored in conf':

    my $parser = sub {
        my $path = shift;

        open my $fh, '<', $path or die "Could not open $path: $!";


        my %conf;

        # .... read the values into %conf


        return \%conf;
    }

SEE ALSO

MooseX::ConfigCascade::Util Moose MooseX::ClassAttribute

AUTHOR

Tom Gracey <tomgracey@gmail.com>

COPYRIGHT AND LICENSE

Copyright (C) 2017 by Tom Gracey

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