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

NAME

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

VERSION

version 3.100452

SYNOPSIS

  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

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

get_resolver_for

This method gets the resolver for the named prefix.

set_resolver_for

This method sets the resolver for the named prefix, replacing any that already existed.

add_resolver_for

This method sets the resolver for the named prefix, throwing an exception if one already exists.

has_resolver_for

This method returns true if a resolver exists for the given prefix.

delete_resolver_for

This method deletes the resolver for the named prefix.

WHAT'S THE POINT?

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

Ricardo Signes <rjbs@cpan.org>

COPYRIGHT AND LICENSE

This software is copyright (c) 2011 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.