Path::Resolver - go from "file" names to things


version 3.100454


Path::Resolver is a set of libraries for resolving virtual file paths into entities that may be found at those paths. Here's a trivial example:

  use Path::Resolver::Resolver::FileSystem;

  # Create a resolver that looks at the filesystem, starting in /etc
  my $fs = Path::Resolver::Resolver::FileSystem->new({ root => '/etc' });

  my $file = $fs->entity_at('/postfix/');

Assuming it exists, this will return an object representing the file /etc/postfix/ Using the code above, $file would be a Path::Resolver::SimpleEntity object, which has a content method. We could print the contents of the file to screen like this:

  print $file->content;


Path::Resolver lets you use a simple, familiar notation for accessing all kinds of hierarchical data. It's also distributed with resolvers that act as multiplexers for other resolvers. Since all resolvers share one mechanism for addressing content, they can easily be mixed and matched. Since resolvers know what kind of object they'll return, and can be fitted with translators, it's easy to ensure that all your multiplexed resolvers will resolve names to the same kind of object.

For example, we could overlay two search paths like this:

  my $resolver = Path::Resolver::Resolver::Mux::Ordered->new({
    resolvers => [
      Path::Resolver::Resolver::FileSystem->new({ root => './config' }),
      Path::Resolver::Resolver::Archive::Tar->new({ archive => 'config.tgz' }),


This will return an entity representing ./config/foo/bar.txt if it exists. If it doesn't, it will look for foo/bar.txt in the contents of the archive. If that's found, an entity will be returned. Finally, if neither is found, it will return false.

Alternately, you could multiplex based on path:

  my $resolver = Path::Resolver::Resolver::Mux::Prefix->new({
    config   => Path::Resolver::Resolver::FileSystem->new({
      root => '/etc/my-app',

    template => Path::Resolver::Resolver::Mux::Ordered->new({
      Path::Resolver::Resolver::DistDir->new({ module => 'MyApp' }),
      Path::Resolver::Resolver::DataSection->new({ module => 'My::Framework' }),

The path /config/ would be looked for on disk as /etc/my-app/ The path /template/main.html would be looked for first as main.html in the sharedir for MyApp and failing that in the DATA section of My::Framework.


If you want to read about how to write a resolver, look at Path::Resolver::Role::Resolver.

If you want to read about the interfaces to the existing resolvers look at their documentation:


Ricardo Signes <>


This software is copyright (c) 2013 by Ricardo Signes.

This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.