08 Jul 2012 18:29:34 UTC
- Distribution: URI-ImpliedBase
- Module version: 0.08
- Source (raw)
- Browse (raw)
- How to Contribute
- Testers (426 / 0 / 0)
- KwaliteeBus factor: 1
- 100.00% Coverage
- License: artistic_1
- Activity24 month
- Download (11.92KB)
- MetaCPAN Explorer
- Subscribe to distribution
- This version
- Latest versionMCMAHON Joe McMahonand 1 contributors
- Joe McMahon (firstname.lastname@example.org)
- SEE ALSO
- CLASS METHODS
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.
You can force a new base at any time by calling
See the section for typical usage.
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.
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 email@example.com 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.
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::ImpliedBaseguesses 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::ImpliedBaseuses 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_soap; this code has not been tested in these environments.
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.
Returns the currently-derived base URI.
Deletes the current implied base.
Module Install Instructions
To install URI::ImpliedBase, copy and paste the appropriate command in to your terminal.
perl -MCPAN -e shell install URI::ImpliedBase
For more information on module installation, please visit the detailed CPAN module installation guide.