Path::Resolver::Resolver::Mux::Prefix - multiplex resolvers by using path prefix


Path-Resolver documentation  | view source Contained in the Path-Resolver distribution.

Index


NAME

Top

Path::Resolver::Resolver::Mux::Prefix - multiplex resolvers by using path prefix

VERSION

Top

version 3.100451

SYNOPSIS

Top

  my $resolver = Path::Resolver::Resolver::Mux::Prefix->new({
    prefixes => {
      foo => $foo_resolver,
      bar => $bar_resolver,
    },
  });

  my $simple_entity = $resolver->entity_at('foo/bar.txt');

This resolver looks at the first part of paths it's given to resolve. It uses that part to find a resolver (by looking it up in the prefixes) and then uses that resolver to resolver the rest of the path.

The default native type of this resolver is Any, meaning that is is much more lax than other resolvers. A native_type can be specified while creating the resolver.

ATTRIBUTES

Top

prefixes

This is a hashref of path prefixes with the resolver that should be used for paths under that prefix. If a resolver is given for the empty prefix, it will be used for content that did not begin with registered prefix.

METHODS

Top

get_resolver_for

This method gets the resolver for the named prefix.

set_resolver_for

This method sets the resolver for the named prefix.

delete_resolver_for

This method deletes the resolver for the named prefix.

WHAT'S THE POINT?

Top

This multiplexer allows you to set up a virtual filesystem in which each subtree is handled by a different resolver. For example:

  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/main.cf would be looked for on disk as /etc/my-app/main.cf. 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.

This kind of resolver allows you to provide a very simple API (that is, filenames) to find all manner of resources, either files or otherwise.

AUTHOR

Top

Ricardo Signes <rjbs@cpan.org>

COPYRIGHT AND LICENSE

Top


Path-Resolver documentation  | view source Contained in the Path-Resolver distribution.