URI::file (3)
Leading comments
Automatically generated by Pod::Man 4.09 (Pod::Simple 3.35) Standard preamble: ========================================================================
NAME
URI::file - URI that maps to local file namesSYNOPSIS
use URI::file; $u1 = URI->new("file:/foo/bar"); $u2 = URI->new("foo/bar", "file"); $u3 = URI::file->new($path); $u4 = URI::file->new("c:\\windows\\", "win32"); $u1->file; $u1->file("mac");
DESCRIPTION
The "URI::file" class supports "URI" objects belonging to the fileIf you simply want to construct file
- $u = URI::file->new( $filename, [$os] )
-
Maps a file name to the file: URIname space, creates aURIobject and returns it. The $filename is interpreted as belonging to the indicated operating system ($os), which defaults to the value of the $^O variable. The $filename can be either absolute or relative, and the corresponding type ofURIobject for $os is returned.
- $u = URI::file->new_abs( $filename, [$os] )
-
Same as URI::file->new, but makes sure that the URIreturned represents an absolute file name. If the $filename argument is relative, then the name is resolved relative to the current directory, i.e. this constructor is really the same as:
URI::file->new($filename)->abs(URI::file->cwd);
- $u = URI::file->cwd
-
Returns a file URIthat represents the current working directory. See Cwd.
The following methods are supported for file
- $u->file( [$os] )
-
Returns a file name. It maps from the URIname space to the file name space of the indicated operating system.
It might return "undef" if the name can not be represented in the indicated file system.
- $u->dir( [$os] )
- Some systems use a different form for names of directories than for plain files. Use this method if you know you want to use the name for a directory.
The "URI::file" module can be used to map generic file names to names suitable for the current system. As such, it can work as a nice replacement for the "File::Spec" module. For instance, the following code translates the UNIX-style file name Foo/Bar.pm to a name suitable for the local system:
$file = URI::file->new("Foo/Bar.pm", "unix")->file; die "Can't map filename Foo/Bar.pm for $^O" unless defined $file; open(FILE, $file) || die "Can't open '$file': $!"; # do something with FILE
MAPPING NOTES
Most computer systems today have hierarchically organized file systems. Mapping the names used in these systems to the genericIf the file system has device, volume or drive specifications as the root of the name space, then it makes sense to map them to the authority field of the generic
Another common use of the authority field is to encode the host on which this file name is valid. The host name ``localhost'' is special and generally has the same meaning as a missing or empty authority field. This use is in conflict with using it as a device specification, but can often be resolved for device specifications having characters not legal in plain host names.
File name to
Example 1: The Mac classic (Mac
Mac classic URI ---------- ------------------- :foo:bar <==> foo/bar : <==> ./ ::foo:bar <==> ../foo/bar ::: <==> ../../ foo:bar <==> file:/foo/bar foo:bar: <==> file:/foo/bar/ .. <==> %2E%2E <undef> <== / foo/ <== file:/foo%2F ./foo.txt <== file:/.%2Ffoo.txt
Note that if you want a relative
Example 2: The
UNIX URI ---------- ------------------ foo/bar <==> foo/bar /foo/bar <==> file:/foo/bar /foo/bar <== file://localhost/foo/bar file: ==> ./file: <undef> <== file:/fo%00/bar / <==> file:/
CONFIGURATION VARIABLES
The following configuration variables influence how the class and its methods behave:- %URI::file::OS_CLASS
-
This hash maps OSidentifiers to implementation classes. You might want to add or modify this if you want to plug in your own file handler class. Normally the keys should match the $^O values in use.
If there is no mapping then the ``Unix'' implementation is used.
- $URI::file::DEFAULT_AUTHORITY
-
This determine what ``authority'' string to include in absolute file
URIs. It defaults to "``. If you prefer verbose URIs you might set it
to be ''localhost".
Setting this value to "undef" force behaviour compatible to
URIv1.31 and earlier. In this mode host names inUNCpaths and drive letters are mapped to the authority component on Windows, while we produce authority-less URIs on Unix.
SEE ALSO
COPYRIGHT
Copyright 1995-1998,2004 Gisle Aas.This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.