The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

Data::Resolver::FromDir - resolver for directories in the filesystem

SYNOPSIS

   use Data::Resolver::FromDir;
   my $resolver = Data::Resolver::FromDir->new(root => $path);

   my @list_of_asset_keys = $resolver->list_asset_keys;
   say 'have it' if $resolver->has_asset($key);
   my $asset = $resolver->get($key);

   my @list_of_sub_resolver_keys = $resolver->list_sub_resolver_keys;
   say 'have it' if $resolver->has_sub_resolver($srkey);
   my $sub_resolver = $resolver->get_sub_resolver($srkey);

DESCRIPTION

This class implements a resolver that is fed from a directory in the filesystem. It inherits from Data::Resolver::Base and implements the corresponding methods according to the expected semantics.

The class is provided a path to a directory in the filesystem; files in the directory will be considered valid assets, while sub-directories will be considered valid starting positions for generating sub-resolvers. So, as an example, if there is the following tree of directories/files:

   <root-dir>
   ├── ciao.txt
   └── foo
      ├── bar.txt
      └── galook
         └── final.txt

the corresponding resolver will expose one key for assets (ciao.txt) and one for sub-resolvers (foo). Getting the sub-resolver for foo, it will expose one key for assets (bar.txt) and one for sub-resolvers (galook), and so on.

Keys are allowed to point to files in sub-directories; the syntax for these sub-directories and files is Unix-oriented in all systems.

INTERFACE

This class inherits from Data::Resolver::Base, inheriting all of its methods and overloading the abstract ones, while keeping the expected semantics.

METHODS

get_asset

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

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

get_sub_resolver

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

retrieve the sub-resolver associated to sub-directory $key, as a new object of class Data::Resolver::FromDir.

has_asset

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

test existence of asset (file) for $key.

has_sub_resolver

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

test existence of sub-resolver for sub-directory $key.

list_asset_keys

   sub list_asset_keys        ($self)       { ... }

return a list of file names available from the resolver.

list_sub_resolver_keys

   sub list_sub_resolver_keys ($self)       { ... }

return a list of directory names available as sub-resolvers.

root

   my $dirpath = $obj->root;

The path to the root directory used for the resolver.

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.