Data::Resolver::Base - (abstract) base for resolver classes
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;
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:
get a list of assets ("list_asset_keys") or sub-resolvers ("list_sub_resolver_keys").
check if an asset is present ("has_asset") or if a sub-resolver is present ("has_sub_resolver").
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.
This class composes the role Data::Resolver::RoleComplain, allowing for the optional usage of Ouch.
The following methods are available from the base class.
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.
key
$key
$type
$value
Compound from "complain" in Data::Resolver::RoleComplain.
Compound from "not_found" in Data::Resolver::RoleComplain.
Compound from "use_ouch" in Data::Resolver::RoleComplain.
The following methods are expected to be implemented:
sub get_asset ($self, $key) { ... }
retrieve the asset associated to $key, as a Data::Resolver::Asset.
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.
sub has_asset ($self, $key) { ... }
test existence of asset for $key.
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.
sub list_asset_keys ($self) { ... }
return a list of strings, each representing a valid key for an asset available from the resolver.
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.
Flavio Poletti <flavio@polettix.it>
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.
To install Data::Resolver, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Data::Resolver
CPAN shell
perl -MCPAN -e shell install Data::Resolver
For more information on module installation, please visit the detailed CPAN module installation guide.