NAME

Curio::Role::CHI - Build Curio classes around CHI.

SYNOPSIS

Create a Curio class:

    package MyApp::Service::Cache;
    
    use Curio role => '::CHI';
    
    use Exporter qw( import );
    our @EXPORT = qw( myapp_cache );
    
    add_key geo_ip => (
        driver => 'Memory',
        global => 0,
    );
    
    sub myapp_cache {
        return __PACKAGE__->fetch( @_ )->chi();
    }
    
    1;

Then use your new Curio class elsewhere:

    use MyApp::Service::Cache;
    
    my $chi = myapp_cache('geo_ip');

DESCRIPTION

This role provides all the basics for building a Curio class which wraps around CHI.

Fun fact, this "SYNOPSIS" is functionally identical to "SYNOPSIS" in Curio.

ATTRIBUTES

chi

    my $chi = MyApp::Service::Cache->fetch('geo_ip)->chi();

Holds the CHI object.

CACHING

This role sets the "does_caching" in Curio::Factory and "cache_per_process" in Curio::Factory features.

cache_per_process is important to set since there are quite a few CHI drivers which do not like to be re-used across processes.

You can of course disable these features.

    does_caching 0;
    cache_per_process 0;

NO KEYS

If you'd like to create a CHI Curio class which exposes a single CHI object and does not support keys then here's a slightly altered version of the "SYNOPSIS" to get you started.

Create a Curio class:

    package MyApp::Service::GeoIPCache;
    
    use Curio role => '::CHI';
    
    use Exporter qw( import );
    our @EXPORT = qw( myapp_geo_ip_cache );
    
    default_arguments (
        driver => 'Memory',
        global => 0,
    );
    
    sub myapp_geo_ip_cache {
        return __PACKAGE__->fetch( @_ )->chi();
    }
    
    1;

Then use your new Curio class elsewhere:

    use MyApp::Service::GeoIPCache;
    
    my $chi = myapp_geo_ip_cache();

SUPPORT

Please submit bugs and feature requests to the Curio-Role-CHI GitHub issue tracker:

https://github.com/bluefeet/Curio-Role-CHI/issues

ACKNOWLEDGEMENTS

Thanks to ZipRecruiter for encouraging their employees to contribute back to the open source ecosystem. Without their dedication to quality software development this distribution would not exist.

AUTHORS

    Aran Clary Deltac <aran@bluefeet.dev>

COPYRIGHT AND LICENSE

Copyright (C) 2019 Aran Clary Deltac

This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program. If not, see http://www.gnu.org/licenses/.