URI::ImpliedBase - magically force all URIs to be absolute
use URI::ImpliedBase; # Set the base to search.cpan.org $u = URI::ImpliedBase->new("http://search.cpan.org"); $v = URI::ImpliedBase->new('subdir') print $v->as_string; # prints http://search.cpan.org/subdir # No default now URI::ImpliedBase->clear(); # Force current working directory to be the URI $w = URI::ImpliedBase->new("../wsdl/test.wsdl"); print $w->as_string; # prints (e.g.) file:///Users/joe/wsdl/test.wsdl
This module is a drop-in replacement for URI. It wraps the new() method with some extra code which automatically captures either the base of the supplied URI (if it is absolute), or supplies the current base to URI-new_abs()> (if it is relative). If the current base is unset when a relative URI is supplied, the current working directory is used to build a "file:" URI and this is saved as the current base.
URI-
You can force a new base at any time by calling URI::ImpliedBase-clear()>.
URI::ImpliedBase-
See the section for typical usage.
Whether or not the current directory stuff works for a non-UNIX OS is currently unknown.
The base is stored internally at the moment; this may be problematic for multi-threaded code.
Contact the author for support on an informal basis. No guarantee of response in a timely fashion.
Joe McMahon mcmahon@ibiblio.org http://ibiblio.org/mcmahon
This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
The full text of the license can be found in the LICENSE file included with this module.
perl(1), perldoc URI.
perldoc
The new method uses URI-new()> to convert the incoming string into a URI object. It extracts the scheme and path if it can, and saves them as the new default base.
If there is no scheme, but there is a path, and there's no existing default base,URI::ImpliedBase guesses that the path is a reference to the local filesystem relative to the current working directory. It saves the current working directory as the base and file: as the scheme, then uses these to build an absolute file: URI and returns it.
URI::ImpliedBase
file:
If there's no scheme, and there is a path, and there is a default base, URI::ImpliedBase uses the default base to convert the path to an absolute URI.
The base is stored in a package lexical, $current_base. This may be a problem for multithreaded code, or code under mod_perl or mod_soap; this code has not been tested in these environments.
$current_base
mod_perl
mod_soap
To install URI::ImpliedBase, copy and paste the appropriate command in to your terminal.
cpanm
cpanm URI::ImpliedBase
CPAN shell
perl -MCPAN -e shell install URI::ImpliedBase
For more information on module installation, please visit the detailed CPAN module installation guide.