NAME

Data::Resolver::Base - (abstract) base for resolver classes

SYNOPSIS

package My::New::Resolver;
use Moo;
extends 'Data::Resolver::Base';

has foo => (is => 'ro', required => 1);
...

sub get_asset              ($self, $key) { ... }
sub get_sub_resolver       ($self, $key) { ... }
sub has_asset              ($self, $key) { ... }
sub has_sub_resolver       ($self, $key) { ... }
sub list_asset_keys        ($self)       { ... }
sub list_sub_resolver_keys ($self)       { ... }

1;

DESCRIPTION

This class, based on Moo, provides a base for deriving resolver classes.

A compliant resolver MUST implement both the asset and the sub-resolver methods. Both types of elements from a resolver support three kind of operations:

listing

get a list of assets ("list_asset_keys") or sub-resolvers ("list_sub_resolver_keys").

checking for existence of a key

check if an asset is present ("has_asset") or if a sub-resolver is present ("has_sub_resolver").

retrieval

get an asset as a Data::Resolver::Asset ("get_asset"), or get a sub-resolver ("get_sub_resolver"). In the latter case, the result is supposed to be compliant to this interface, although it might be of a different class from the starting object.

Retrieval functions are supposed to throw an exception if the corresponding key is not present; to this extent, the class composes "complain" and "not_found" from Data::Resolver::RoleComplain.

INTERFACE

This class composes the role Data::Resolver::RoleComplain, allowing for the optional usage of Ouch.

METHODS

The following methods are available from the base class.

asset

my $asset = $obj->asset($key, $type, $value);

create an instance of class Data::Resolver::Asset, setting the key to the provided $key, setting slot $type with the provided $value, and propagating the configurations for Data::Resolver::RoleComplain.

complain

Compound from "complain" in Data::Resolver::RoleComplain.

not_found

Compound from "not_found" in Data::Resolver::RoleComplain.

use_ouch

Compound from "use_ouch" in Data::Resolver::RoleComplain.

ABSTRACT METHODS

The following methods are expected to be implemented:

get_asset

sub get_asset              ($self, $key) { ... }

retrieve the asset associated to $key, as a Data::Resolver::Asset.

get_sub_resolver

sub get_sub_resolver       ($self, $key) { ... }

retrieve the sub-resolver associated to $key. It's supposed to be an object that supports the same interface as any resolver, i.e. to derive from this class too.

If sub-resolvers are not supported, this function MUST always throw an exception.

has_asset

sub has_asset              ($self, $key) { ... }

test existence of asset for $key.

has_sub_resolver

sub has_sub_resolver       ($self, $key) { ... }

test existence of sub-resolver for $key.

If sub-resolvers are not supported, this function MUST always return a false value.

list_asset_keys

sub list_asset_keys        ($self)       { ... }

return a list of strings, each representing a valid key for an asset available from the resolver.

list_sub_resolver_keys

sub list_sub_resolver_keys ($self)       { ... }

return a list of strings, each representing a valid key for a sub-resolver available from the resolver.

If sub-resolvers are not supported, this function MUST always return an empty list.

AUTHOR

Flavio Poletti <flavio@polettix.it>

COPYRIGHT AND LICENSE

Copyright 2023 by Flavio Poletti <flavio@polettix.it>

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.