URI::ImpliedBase - magically force all URIs to be absolute


URI-ImpliedBase documentation  | view source Contained in the URI-ImpliedBase distribution.

Index


NAME

Top

URI::ImpliedBase - magically force all URIs to be absolute

SYNOPSIS

Top

  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

Top

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

Top

See the SYNOPSIS section for typical usage.

BUGS

Top

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

Top

Contact the author for support on an informal basis. No guarantee of response in a timely fashion.

AUTHOR

Top

	Joe McMahon
	mcmahon@ibiblio.org
	http://ibiblio.org/mcmahon

COPYRIGHT

Top

SEE ALSO

Top

perl(1), perldoc URI.

CLASS METHODS

Top

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

Top

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.


URI-ImpliedBase documentation  | view source Contained in the URI-ImpliedBase distribution.