NAME

Database::BI::CacheDir - Where a cache keeps its files

VERSION

0.023.1

SYNOPSIS

use Database::BI::CacheDir;

sub new {
    my ($class, %args) = @_;
    my $dir = Database::BI::CacheDir::resolve(
        class   => $class,
        params  => \%args,
        default => '.bi/geocode-cache',
    );
    ...
}

DESCRIPTION

Every object in this distribution that keeps a cache on disc asks resolve() for its directory when it is made, so one setting moves them all.

SUBROUTINES

resolve

Returns the first of these that is set:

1. cache_dir from Object::Configure for class: its config files (~/.conf/<class>.yml and the rest), then the environment variable <Class>__cache_dir (:: written __, e.g. Database__BI__Model__Geocode__cache_dir). A cache_dir in params is what those fall back on;
2. $ENV{CACHEDIR};
3. $ENV{CACHE_DIR};
4. cache_dir in database_bi.conf; a relative one is under the application home;
5. default.

The directory is not made here; the cache makes it when it first stores something.

API SPECIFICATION

INPUT

class   => string,   # optional; the class being made, for Object::Configure
params  => hashref,  # optional; the arguments to its new(), read for cache_dir
config  => hashref,  # optional; the application's config; when the key is absent, database_bi.conf is read (see bi_config)
home    => string,   # optional; the folder a relative config cache_dir is under
default => string,   # optional; the directory when nothing else is set

OUTPUT

A directory name, or undef when nothing is set and there is no default. A config file Object::Configure cannot read is reported with carp and skipped.

bi_config

my ($config, $home) = Database::BI::CacheDir::bi_config();

The application's configuration for a caller outside it: the file $ENV{MOJO_CONFIG} names, else database_bi.conf in the current directory.

API SPECIFICATION

INPUT

None.

OUTPUT

($config_hashref, $home), where $home is the file's folder; an empty list when there is no file or it does not read (the second is reported with carp).

AUTHOR

Nigel Horne <njh@nigelhorne.com>

LICENCE AND COPYRIGHT

Copyright 2026 Nigel Horne.

Usage is subject to the GPL2 licence terms.