NAME
URI::ImpliedBase - magically force all URIs to be absolute
SYNOPSIS
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
DESCRIPTION
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.
You can force a new base at any time by calling URI::ImpliedBase-
clear()>.
USAGE
See the section for typical usage.
NOTES
Each time you call URI::ImpliedBase->new(), URI::ImpliedBase checks the scheme of the supplied URL against @URI::ImpliedBase::accepted_schemes. If the scheme of the new URI is in the list of accepted schemes, we update the base.
The initial set of schemes which update the base are 'http' and 'https'. You may update the list of schemes by altering @URI::ImpliedBase::accepted_schemes.
BUGS
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.
SUPPORT
Contact the author for support on an informal basis. No guarantee of response in a timely fashion.
AUTHOR
Joe McMahon
mcmahon@ibiblio.org
http://ibiblio.org/mcmahon
COPYRIGHT
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.
SEE ALSO
perl(1), perldoc
URI.
CLASS METHODS
new
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.
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.
METHODS
new
Accepts a URI and figures out what the proper base is for it.
If the scheme is defined, we can just save the current URI as the base. If there's a path but no scheme, we have to determine the proper base: if the base has already been determined by a previous call, then we use that. Otherwise we figure out the current working directory and use that.
current_base
Returns the currently-derived base URI.
clear
Deletes the current implied base.