home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Chip 2000 May
/
Chip_2000-05_cd1.bin
/
zkuste
/
Perl
/
ActivePerl-5.6.0.613.msi
/
䆊䌷䈹䈙䏵-䞅䞆䞀㡆䞃䄦䠥
/
_025c7bb85b022b8c07f09ad5c26a7cea
< prev
next >
Wrap
Text File
|
2000-03-23
|
9KB
|
202 lines
<HTML>
<HEAD>
<TITLE>URI::file - URI that map to local file names</TITLE>
<LINK REL="stylesheet" HREF="../../../Active.css" TYPE="text/css">
<LINK REV="made" HREF="mailto:">
</HEAD>
<BODY>
<TABLE BORDER=0 CELLPADDING=0 CELLSPACING=0 WIDTH=100%>
<TR><TD CLASS=block VALIGN=MIDDLE WIDTH=100% BGCOLOR="#cccccc">
<STRONG><P CLASS=block> URI::file - URI that map to local file names</P></STRONG>
</TD></TR>
</TABLE>
<A NAME="__index__"></A>
<!-- INDEX BEGIN -->
<UL>
<LI><A HREF="#name">NAME</A></LI><LI><A HREF="#supportedplatforms">SUPPORTED PLATFORMS</A></LI>
<LI><A HREF="#synopsis">SYNOPSIS</A></LI>
<LI><A HREF="#description">DESCRIPTION</A></LI>
<LI><A HREF="#mapping notes">MAPPING NOTES</A></LI>
<LI><A HREF="#see also">SEE ALSO</A></LI>
<LI><A HREF="#copyright">COPYRIGHT</A></LI>
</UL>
<!-- INDEX END -->
<HR>
<P>
<H1><A NAME="name">NAME</A></H1>
<P>URI::file - URI that map to local file names</P>
<P>
<HR>
<H1><A NAME="supportedplatforms">SUPPORTED PLATFORMS</A></H1>
<UL>
<LI>Linux</LI>
<LI>Solaris</LI>
<LI>Windows</LI>
</UL>
<HR>
<H1><A NAME="synopsis">SYNOPSIS</A></H1>
<PRE>
use URI::file;</PRE>
<PRE>
$u1 = URI->new("<A HREF="file:/foo/bar"">file:/foo/bar"</A>;);
$u2 = URI->new("foo/bar", "file");</PRE>
<PRE>
$u3 = URI::file->new($path);
$u4 = URI::file->new("c:\\windows\\", "win32");
</PRE>
<PRE>
$u1->file;
$u1->file("mac");</PRE>
<P>
<HR>
<H1><A NAME="description">DESCRIPTION</A></H1>
<P>The <CODE>URI::file</CODE> class supports <CODE>URI</CODE> objects belonging to the <EM>file</EM>
URI scheme. This scheme allows us to map the conventional file names
found on various computer systems to the URI name space. An old
specification of the <EM>file</EM> URI scheme is found in RFC 1738. Some
older background information is also in RFC 1630. There are no newer
specifications as far as I know.</P>
<P>If you want simply to construct <EM>file</EM> URI objects from URI strings,
use the normal <CODE>URI</CODE> constructor. If you want to construct <EM>file</EM>
URI objects from the actual file names used by various systems, then
use one of the following <CODE>URI::file</CODE> constructors:</P>
<DL>
<DT><STRONG><A NAME="item_new">$u = URI::file->new( $filename, [$os] )</A></STRONG><BR>
<DD>
Maps a file name to the <EM>file:</EM> URI name space, creates an URI object
and returns it. The $filename is interpreted as one 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 of URI object for $os is returned.
<P></P>
<DT><STRONG><A NAME="item_new_abs">$u = URI::file->new_abs( $filename, [$os] )</A></STRONG><BR>
<DD>
Same as URI::file->new, but will make sure that the URI returned
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:
<PRE>
URI::file->new($filename)->abs(URI::file->cwd);</PRE>
<P></P>
<DT><STRONG><A NAME="item_cwd">$u = URI::file->cwd</A></STRONG><BR>
<DD>
Returns a <EM>file</EM> URI that represents the current working directory.
See <A HREF="../../../lib/Cwd.html">the Cwd manpage</A>.
<P></P></DL>
<P>The following methods are supported for <EM>file</EM> URI (in addition to
the common and generic methods described in <A HREF="../../../site/lib/URI.html">the URI manpage</A>):</P>
<DL>
<DT><STRONG><A NAME="item_file">$u->file( [$os] )</A></STRONG><BR>
<DD>
This method return a file name. It maps from the URI name space
to the file name space of the indicated operating system.
<P>It might return U<undef> if the name can not be represented in the
indicated file system.</P>
<P></P>
<DT><STRONG><A NAME="item_dir">$u->dir( [$os] )</A></STRONG><BR>
<DD>
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.
<P></P></DL>
<P>The <CODE>URI::file</CODE> 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 <CODE>File::Spec</CODE> module. For instance the following
code will translate the Unix style file name <EM>Foo/Bar.pm</EM> to a name
suitable for the local system.</P>
<PRE>
$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</PRE>
<P>
<HR>
<H1><A NAME="mapping notes">MAPPING NOTES</A></H1>
<P>Most computer systems today have hierarchically organized file systems.
Mapping the names used in these systems to the generic URI syntax
allows us to work with relative file URIs that behave as they should
when resolved using the generic algorithm for URIs (specified in RFC
2396). Mapping a file name to the generic URI syntax involves mapping
the path separator character to ``/'' and encoding of any reserved
characters that appear in the path segments of the file names. If
path segments consisting of the strings ``.'' or ``..'' have a
different meaning than what is specified for generic URIs, then these
must be encoded as well.</P>
<P>If 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 URI syntax. This makes sure that
relative URI can not be resolved ``above'' them , i.e. generally how
relative file names work in those systems.</P>
<P>Another common use of the authority field is to encode the host that
this file name is valid on. The host name ``localhost'' is special and
generally have the same meaning as an missing or empty authority
field. This use will be 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.</P>
<P>File name to URI mapping in normally not one-to-one. There are
usually many URI that map to the same file name. For instance an
authority of ``localhost'' maps the same as a URI with a missing or empty
authority.</P>
<P>Example 1: The Mac use ``:'' as path separator, but not in the same way
as generic URI. ``:foo'' is a relative name. ``foo:bar'' is an absolute
name. Also path segments can contain the ``/'' character as well as be
literal ``.'' or ``..''. It means that we will map like this:</P>
<PRE>
Mac URI
---------- -------------------
:foo:bar <==> foo/bar
: <==> ./
::foo:bar <==> ../foo/bar
::: <==> ../../
foo:bar <==> <A HREF="file:/foo/bar">file:/foo/bar</A>
foo:bar: <==> <A HREF="file:/foo/bar/">file:/foo/bar/</A>
.. <==> %2E%2E
<undef> <== /
foo/ <== <A HREF="file:/foo%2F">file:/foo%2F</A>
./foo.txt <== <A HREF="file:/.%2Ffoo.txt">file:/.%2Ffoo.txt</A>
</PRE>
<PRE>
Note that if you want a relative URL, you *must* begin the path with a :. Any
path that begins with [^:] will be treated as absolute.</PRE>
<P>Example 2: The Unix file system is easy to map as it use the same path
separator as URIs, have a single root, and segments of ``.'' and ``..''
have the same meaning. URIs that have the character ``\0'' or ``/'' as
part of any path segment can not be turned into valid Unix file names.</P>
<PRE>
Unix URI
---------- ------------------
foo/bar <==> foo/bar
/foo/bar <==> <A HREF="file:/foo/bar">file:/foo/bar</A>
/foo/bar <== <A HREF="file://localhost/foo/bar">file://localhost/foo/bar</A>
file: ==> ./file:
<undef> <== <A HREF="file:/fo%00/bar">file:/fo%00/bar</A>
/ <==> <A HREF="file:/">file:/</A></PRE>
<P>
<HR>
<H1><A NAME="see also">SEE ALSO</A></H1>
<P><A HREF="../../../site/lib/URI.html">the URI manpage</A>, <A HREF="../../../lib/File/Spec.html">the File::Spec manpage</A>, <A HREF="../../../lib/Pod/perlport.html">the perlport manpage</A></P>
<P>
<HR>
<H1><A NAME="copyright">COPYRIGHT</A></H1>
<P>Copyright 1995-1998 Gisle Aas.</P>
<P>This library is free software; you can redistribute it and/or
modify it under the same terms as Perl itself.</P>
<TABLE BORDER=0 CELLPADDING=0 CELLSPACING=0 WIDTH=100%>
<TR><TD CLASS=block VALIGN=MIDDLE WIDTH=100% BGCOLOR="#cccccc">
<STRONG><P CLASS=block> URI::file - URI that map to local file names</P></STRONG>
</TD></TR>
</TABLE>
</BODY>
</HTML>