Path::Resolver::Resolver::Mux::Prefix - multiplex resolvers by using path prefix
version 3.100455
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.
prefixes
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.
native_type
This library should run on perls released even a long time ago. It should work on any version of perl released in the last five years.
Although it may work on older versions of perl, no guarantee is made that the minimum required version will not be increased. The version may be increased for any reason, and there is no promise that patches will be accepted to lower the minimum required perl.
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.
This method gets the resolver for the named prefix.
This method sets the resolver for the named prefix, replacing any that already existed.
This method sets the resolver for the named prefix, throwing an exception if one already exists.
This method returns true if a resolver exists for the given prefix.
This method deletes the resolver for the named prefix.
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.
Ricardo Signes <cpan@semiotic.systems>
This software is copyright (c) 2022 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.
To install Path::Resolver, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Path::Resolver
CPAN shell
perl -MCPAN -e shell install Path::Resolver
For more information on module installation, please visit the detailed CPAN module installation guide.