The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.
[%#
  # IMPORTANT NOTE
  #   This documentation is generated automatically from source
  #   templates.  Any changes you make here may be lost.
  # 
  #   The 'docsrc' documentation source bundle is available for download
  #   from http://www.template-toolkit.org/docs.html and contains all
  #   the source templates, XML files, scripts, etc., from which the
  #   documentation for the Template Toolkit is built.
-%]
[% META book = 'Modules'
        page = 'Plugin_File'
%]
[%  WRAPPER toc;
	PROCESS tocitem 
	        title ="SYNOPSIS"
                subs  = [];
	PROCESS tocitem 
	        title ="DESCRIPTION"
                subs  = [];
	PROCESS tocitem 
	        title ="EXAMPLES"
                subs  = [];
	PROCESS tocitem 
	        title ="AUTHORS"
                subs  = [];
	PROCESS tocitem 
	        title ="VERSION"
                subs  = [];
	PROCESS tocitem 
	        title ="COPYRIGHT"
                subs  = [];
	PROCESS tocitem 
	        title ="SEE ALSO"
                subs  = [];
    END
%]
<!-- Pod to HTML conversion by the Template Toolkit version 2 -->
[% WRAPPER section
    title="SYNOPSIS"
-%]<pre>    [% tt_start_tag %] USE File(filepath) [% tt_end_tag %]
    [% tt_start_tag %] File.path [% tt_end_tag %]         # full path
    [% tt_start_tag %] File.name [% tt_end_tag %]	    # filename
    [% tt_start_tag %] File.dir [% tt_end_tag %]          # directory</pre>
[%- END %]
[% WRAPPER section
    title="DESCRIPTION"
-%]<p>
This plugin provides an abstraction of a file.  It can be used to 
fetch details about files from the file system, or to represent abstract
files (e.g. when creating an index page) that may or may not exist on 
a file system.
</p>
<p>
A file name or path should be specified as a constructor argument.  e.g.
</p>
<pre>    [% tt_start_tag %] USE File('foo.html') [% tt_end_tag %]
    [% tt_start_tag %] USE File('foo/bar/baz.html') [% tt_end_tag %]
    [% tt_start_tag %] USE File('/foo/bar/baz.html') [% tt_end_tag %]</pre>
<p>
The file should exist on the current file system (unless 'nostat'
option set, see below) as an absolute file when specified with as
leading '/' as per '/foo/bar/baz.html', or otherwise as one relative
to the current working directory.  The constructor performs a stat()
on the file and makes the 13 elements returned available as the plugin
items:
</p>
<pre>    dev ino mode nlink uid gid rdev size 
    atime mtime ctime blksize blocks</pre>
<p>
e.g.
</p>
<pre>    [% tt_start_tag %] USE File('/foo/bar/baz.html') [% tt_end_tag %]</pre>
<pre>    [% tt_start_tag %] File.mtime [% tt_end_tag %]
    [% tt_start_tag %] File.mode [% tt_end_tag %]
    ...</pre>
<p>
In addition, the 'user' and 'group' items are set to contain the user
and group names as returned by calls to getpwuid() and getgrgid() for
the file 'uid' and 'gid' elements, respectively.  On Win32 platforms
on which getpwuid() and getgrid() are not available, these values are
undefined.
</p>
<pre>    [% tt_start_tag %] USE File('/tmp/foo.html') [% tt_end_tag %]
    [% tt_start_tag %] File.uid [% tt_end_tag %]	# e.g. 500
    [% tt_start_tag %] File.user [% tt_end_tag %]     # e.g. abw</pre>
<p>
This user/group lookup can be disabled by setting the 'noid' option.
</p>
<pre>    [% tt_start_tag %] USE File('/tmp/foo.html', noid=1) [% tt_end_tag %]
    [% tt_start_tag %] File.uid [% tt_end_tag %]	# e.g. 500
    [% tt_start_tag %] File.user [% tt_end_tag %]     # nothing</pre>
<p>
The 'isdir' flag will be set if the file is a directory.
</p>
<pre>    [% tt_start_tag %] USE File('/tmp') [% tt_end_tag %]
    [% tt_start_tag %] File.isdir [% tt_end_tag %]	# 1</pre>
<p>
If the stat() on the file fails (e.g. file doesn't exists, bad
permission, etc) then the constructor will throw a 'File' exception.
This can be caught within a TRY...CATCH block.
</p>
<pre>    [% tt_start_tag %] TRY [% tt_end_tag %]
       [% tt_start_tag %] USE File('/tmp/myfile') [% tt_end_tag %]
       File exists!
    [% tt_start_tag %] CATCH File [% tt_end_tag %]
       File error: [% tt_start_tag %] error.info [% tt_end_tag %]
    [% tt_start_tag %] END [% tt_end_tag %]</pre>
<p>
Note the capitalisation of the exception type, 'File' to indicate an
error thrown by the 'File' plugin, to distinguish it from a regular
'file' exception thrown by the Template Toolkit.
</p>
<p>
Note that the 'File' plugin can also be referenced by the lower case
name 'file'.  However, exceptions are always thrown of the 'File'
type, regardless of the capitalisation of the plugin named used.
</p>
<pre>    [% tt_start_tag %] USE file('foo.html') [% tt_end_tag %]
    [% tt_start_tag %] file.mtime [% tt_end_tag %]</pre>
<p>
As with any other Template Toolkit plugin, an alternate name can be 
specified for the object created.
</p>
<pre>    [% tt_start_tag %] USE foo = file('foo.html') [% tt_end_tag %]
    [% tt_start_tag %] foo.mtime [% tt_end_tag %]</pre>
<p>
The 'nostat' option can be specified to prevent the plugin constructor
from performing a stat() on the file specified.  In this case, the
file does not have to exist in the file system, no attempt will be made
to verify that it does, and no error will be thrown if it doesn't.
The entries for the items usually returned by stat() will be set 
empty.
</p>
<pre>    [% tt_start_tag %] USE file('/some/where/over/the/rainbow.html', nostat=1) 
    [% tt_start_tag %] file.mtime [% tt_end_tag %]     # nothing</pre>
<p>
All File plugins, regardless of the nostat option, have set a number
of items relating to the original path specified.
</p>
<ul>
<li><b>path</b><br>
<p>
The full, original file path specified to the constructor.
</p>
<pre>    [% tt_start_tag %] USE file('/foo/bar.html') [% tt_end_tag %]
    [% tt_start_tag %] file.path [% tt_end_tag %]	# /foo/bar.html</pre>

<li><b>name</b><br>
<p>
The name of the file without any leading directories.
</p>
<pre>    [% tt_start_tag %] USE file('/foo/bar.html') [% tt_end_tag %]
    [% tt_start_tag %] file.name [% tt_end_tag %]	# bar.html</pre>

<li><b>dir</b><br>
<p>
The directory element of the path with the filename removed.
</p>
<pre>    [% tt_start_tag %] USE file('/foo/bar.html') [% tt_end_tag %]
    [% tt_start_tag %] file.name [% tt_end_tag %]	# /foo</pre>

<li><b>ext</b><br>
<p>
The file extension, if any, appearing at the end of the path following 
a '.' (not included in the extension).
</p>
<pre>    [% tt_start_tag %] USE file('/foo/bar.html') [% tt_end_tag %]
    [% tt_start_tag %] file.ext [% tt_end_tag %]	# html</pre>

<li><b>home</b><br>
<p>
This contains a string of the form '../..' to represent the upward path
from a file to its root directory.
</p>
<pre>    [% tt_start_tag %] USE file('bar.html') [% tt_end_tag %]
    [% tt_start_tag %] file.home [% tt_end_tag %]	# nothing</pre>
<pre>    [% tt_start_tag %] USE file('foo/bar.html') [% tt_end_tag %]
    [% tt_start_tag %] file.home [% tt_end_tag %]	# ..</pre>
<pre>    [% tt_start_tag %] USE file('foo/bar/baz.html') [% tt_end_tag %]
    [% tt_start_tag %] file.home [% tt_end_tag %]	# ../..</pre>

<li><b>root</b><br>
<p>
The 'root' item can be specified as a constructor argument, indicating
a root directory in which the named file resides.  This is otherwise
set empty.
</p>
<pre>    [% tt_start_tag %] USE file('foo/bar.html', root='/tmp') [% tt_end_tag %]
    [% tt_start_tag %] file.root [% tt_end_tag %]	# /tmp</pre>

<li><b>abs</b><br>
<p>
This returns the absolute file path by constructing a path from the 
'root' and 'path' options.
</p>
<pre>    [% tt_start_tag %] USE file('foo/bar.html', root='/tmp') [% tt_end_tag %]
    [% tt_start_tag %] file.path [% tt_end_tag %]	# foo/bar.html
    [% tt_start_tag %] file.root [% tt_end_tag %]	# /tmp
    [% tt_start_tag %] file.abs [% tt_end_tag %]	# /tmp/foo/bar.html</pre>

</ul>
<p>
In addition, the following method is provided:
</p>
<ul>
<li><b>rel(path)</b><br>
<p>
This returns a relative path from the current file to another path specified
as an argument.  It is constructed by appending the path to the 'home' 
item.
</p>
<pre>    [% tt_start_tag %] USE file('foo/bar/baz.html') [% tt_end_tag %]
    [% tt_start_tag %] file.rel('wiz/waz.html') [% tt_end_tag %]	# ../../wiz/waz.html</pre>

</ul>
[%- END %]
[% WRAPPER section
    title="EXAMPLES"
-%]<pre>    [% tt_start_tag %] USE file('/foo/bar/baz.html') [% tt_end_tag %]</pre>
<pre>    [% tt_start_tag %] file.path  [% tt_end_tag %]      # /foo/bar/baz.html
    [% tt_start_tag %] file.dir   [% tt_end_tag %]      # /foo/bar
    [% tt_start_tag %] file.name  [% tt_end_tag %]      # baz.html
    [% tt_start_tag %] file.home  [% tt_end_tag %]      # ../..
    [% tt_start_tag %] file.root  [% tt_end_tag %]      # ''
    [% tt_start_tag %] file.abs   [% tt_end_tag %]      # /foo/bar/baz.html
    [% tt_start_tag %] file.ext   [% tt_end_tag %]      # html
    [% tt_start_tag %] file.mtime [% tt_end_tag %]	  # 987654321
    [% tt_start_tag %] file.atime [% tt_end_tag %]      # 987654321
    [% tt_start_tag %] file.uid   [% tt_end_tag %]      # 500
    [% tt_start_tag %] file.user  [% tt_end_tag %]      # abw</pre>
<pre>    [% tt_start_tag %] USE file('foo.html') [% tt_end_tag %]</pre>
<pre>    [% tt_start_tag %] file.path [% tt_end_tag %]	      # foo.html
    [% tt_start_tag %] file.dir  [% tt_end_tag %]       # ''
    [% tt_start_tag %] file.name [% tt_end_tag %]	      # foo.html
    [% tt_start_tag %] file.root [% tt_end_tag %]       # ''
    [% tt_start_tag %] file.home [% tt_end_tag %]       # ''
    [% tt_start_tag %] file.abs  [% tt_end_tag %]       # foo.html</pre>
<pre>    [% tt_start_tag %] USE file('foo/bar/baz.html') [% tt_end_tag %]</pre>
<pre>    [% tt_start_tag %] file.path [% tt_end_tag %]	      # foo/bar/baz.html
    [% tt_start_tag %] file.dir  [% tt_end_tag %]       # foo/bar
    [% tt_start_tag %] file.name [% tt_end_tag %]	      # baz.html
    [% tt_start_tag %] file.root [% tt_end_tag %]       # ''
    [% tt_start_tag %] file.home [% tt_end_tag %]       # ../..
    [% tt_start_tag %] file.abs  [% tt_end_tag %]       # foo/bar/baz.html</pre>
<pre>    [% tt_start_tag %] USE file('foo/bar/baz.html', root='/tmp') [% tt_end_tag %]</pre>
<pre>    [% tt_start_tag %] file.path [% tt_end_tag %]	      # foo/bar/baz.html
    [% tt_start_tag %] file.dir  [% tt_end_tag %]       # foo/bar
    [% tt_start_tag %] file.name [% tt_end_tag %]	      # baz.html
    [% tt_start_tag %] file.root [% tt_end_tag %]       # /tmp
    [% tt_start_tag %] file.home [% tt_end_tag %]       # ../..
    [% tt_start_tag %] file.abs  [% tt_end_tag %]       # /tmp/foo/bar/baz.html</pre>
<pre>    # calculate other file paths relative to this file and its root
    [% tt_start_tag %] USE file('foo/bar/baz.html', root =&gt; '/tmp/tt2') [% tt_end_tag %]</pre>
<pre>    [% tt_start_tag %] file.path('baz/qux.html') [% tt_end_tag %]	    # ../../baz/qux.html
    [% tt_start_tag %] file.dir('wiz/woz.html')  [% tt_end_tag %]     # ../../wiz/woz.html</pre>
[%- END %]
[% WRAPPER section
    title="AUTHORS"
-%]<p>
Michael Stevens &lt;michael@etla.org&gt; wrote the original Directory plugin
on which this is based.  Andy Wardley &lt;abw@wardley.org&gt; split it into 
separate File and Directory plugins, added some extra code and documentation
for VIEW support, and made a few other minor tweaks.
</p>
[%- END %]
[% WRAPPER section
    title="VERSION"
-%]<p>
2.71, distributed as part of the
Template Toolkit version 2.19, released on 27 April 2007.
</p>
[%- END %]
[% WRAPPER section
    title="COPYRIGHT"
-%]<p>
This module is free software; you can redistribute it and/or
modify it under the same terms as Perl itself.
</p>
[%- END %]
[% WRAPPER section
    title="SEE ALSO"
-%]<p>
[% ttlink('Template::Plugin', 'Template::Plugin') -%], [% ttlink('Template::Plugin::Directory', 'Template::Plugin::Directory') -%], [% ttlink('Template::View', 'Template::View') -%]
</p>
[%- END %]