Mini Shell

Direktori : /home/.cpanm/work/1731937184.9052/Template-Toolkit-3.102/blib/man3/
Upload File :
Current File : //home/.cpanm/work/1731937184.9052/Template-Toolkit-3.102/blib/man3/Template::Plugin::File.3pm

.\" Automatically generated by Pod::Man 4.14 (Pod::Simple 3.42)
.\"
.\" Standard preamble:
.\" ========================================================================
.de Sp \" Vertical space (when we can't use .PP)
.if t .sp .5v
.if n .sp
..
.de Vb \" Begin verbatim text
.ft CW
.nf
.ne \\$1
..
.de Ve \" End verbatim text
.ft R
.fi
..
.\" Set up some character translations and predefined strings.  \*(-- will
.\" give an unbreakable dash, \*(PI will give pi, \*(L" will give a left
.\" double quote, and \*(R" will give a right double quote.  \*(C+ will
.\" give a nicer C++.  Capital omega is used to do unbreakable dashes and
.\" therefore won't be available.  \*(C` and \*(C' expand to `' in nroff,
.\" nothing in troff, for use with C<>.
.tr \(*W-
.ds C+ C\v'-.1v'\h'-1p'\s-2+\h'-1p'+\s0\v'.1v'\h'-1p'
.ie n \{\
.    ds -- \(*W-
.    ds PI pi
.    if (\n(.H=4u)&(1m=24u) .ds -- \(*W\h'-12u'\(*W\h'-12u'-\" diablo 10 pitch
.    if (\n(.H=4u)&(1m=20u) .ds -- \(*W\h'-12u'\(*W\h'-8u'-\"  diablo 12 pitch
.    ds L" ""
.    ds R" ""
.    ds C` ""
.    ds C' ""
'br\}
.el\{\
.    ds -- \|\(em\|
.    ds PI \(*p
.    ds L" ``
.    ds R" ''
.    ds C`
.    ds C'
'br\}
.\"
.\" Escape single quotes in literal strings from groff's Unicode transform.
.ie \n(.g .ds Aq \(aq
.el       .ds Aq '
.\"
.\" If the F register is >0, we'll generate index entries on stderr for
.\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index
.\" entries marked with X<> in POD.  Of course, you'll have to process the
.\" output yourself in some meaningful fashion.
.\"
.\" Avoid warning from groff about undefined register 'F'.
.de IX
..
.nr rF 0
.if \n(.g .if rF .nr rF 1
.if (\n(rF:(\n(.g==0)) \{\
.    if \nF \{\
.        de IX
.        tm Index:\\$1\t\\n%\t"\\$2"
..
.        if !\nF==2 \{\
.            nr % 0
.            nr F 2
.        \}
.    \}
.\}
.rr rF
.\" ========================================================================
.\"
.IX Title "Template::Plugin::File 3"
.TH Template::Plugin::File 3 "2024-06-21" "perl v5.32.1" "User Contributed Perl Documentation"
.\" For nroff, turn off justification.  Always turn off hyphenation; it makes
.\" way too many mistakes in technical documents.
.if n .ad l
.nh
.SH "NAME"
Template::Plugin::File \- Plugin providing information about files
.SH "SYNOPSIS"
.IX Header "SYNOPSIS"
.Vb 4
\&    [% USE File(filepath) %]
\&    [% File.path %]         # full path
\&    [% File.name %]         # filename
\&    [% File.dir %]          # directory
.Ve
.SH "DESCRIPTION"
.IX Header "DESCRIPTION"
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.
.PP
A file name or path should be specified as a constructor argument.  e.g.
.PP
.Vb 3
\&    [% USE File(\*(Aqfoo.html\*(Aq) %]
\&    [% USE File(\*(Aqfoo/bar/baz.html\*(Aq) %]
\&    [% USE File(\*(Aq/foo/bar/baz.html\*(Aq) %]
.Ve
.PP
The file should exist on the current file system (unless \f(CW\*(C`nostat\*(C'\fR
option set, see below) as an absolute file when specified with as
leading '\f(CW\*(C`/\*(C'\fR' as per '\f(CW\*(C`/foo/bar/baz.html\*(C'\fR', or otherwise as one relative
to the current working directory.  The constructor performs a \f(CW\*(C`stat()\*(C'\fR
on the file and makes the 13 elements returned available as the plugin
items:
.PP
.Vb 2
\&    dev ino mode nlink uid gid rdev size
\&    atime mtime ctime blksize blocks
.Ve
.PP
e.g.
.PP
.Vb 1
\&    [% USE File(\*(Aq/foo/bar/baz.html\*(Aq) %]
\&
\&    [% File.mtime %]
\&    [% File.mode %]
\&    ...
.Ve
.PP
In addition, the \f(CW\*(C`user\*(C'\fR and \f(CW\*(C`group\*(C'\fR items are set to contain the user
and group names as returned by calls to \f(CW\*(C`getpwuid()\*(C'\fR and \f(CW\*(C`getgrgid()\*(C'\fR for
the file \f(CW\*(C`uid\*(C'\fR and \f(CW\*(C`gid\*(C'\fR elements, respectively.  On Win32 platforms
on which \f(CW\*(C`getpwuid()\*(C'\fR and \f(CW\*(C`getgrid()\*(C'\fR are not available, these values are
undefined.
.PP
.Vb 3
\&    [% USE File(\*(Aq/tmp/foo.html\*(Aq) %]
\&    [% File.uid %]      # e.g. 500
\&    [% File.user %]     # e.g. abw
.Ve
.PP
This user/group lookup can be disabled by setting the \f(CW\*(C`noid\*(C'\fR option.
.PP
.Vb 3
\&    [% USE File(\*(Aq/tmp/foo.html\*(Aq, noid=1) %]
\&    [% File.uid %]      # e.g. 500
\&    [% File.user %]     # nothing
.Ve
.PP
The \f(CW\*(C`isdir\*(C'\fR flag will be set if the file is a directory.
.PP
.Vb 2
\&    [% USE File(\*(Aq/tmp\*(Aq) %]
\&    [% File.isdir %]    # 1
.Ve
.PP
If the \f(CW\*(C`stat()\*(C'\fR on the file fails (e.g. file doesn't exists, bad
permission, etc) then the constructor will throw a \f(CW\*(C`File\*(C'\fR exception.
This can be caught within a \f(CW\*(C`TRY...CATCH\*(C'\fR block.
.PP
.Vb 6
\&    [% TRY %]
\&       [% USE File(\*(Aq/tmp/myfile\*(Aq) %]
\&       File exists!
\&    [% CATCH File %]
\&       File error: [% error.info %]
\&    [% END %]
.Ve
.PP
Note the capitalisation of the exception type, '\f(CW\*(C`File\*(C'\fR', to indicate an
error thrown by the \f(CW\*(C`File\*(C'\fR plugin, to distinguish it from a regular
\&\f(CW\*(C`file\*(C'\fR exception thrown by the Template Toolkit.
.PP
Note that the \f(CW\*(C`File\*(C'\fR plugin can also be referenced by the lower case
name '\f(CW\*(C`file\*(C'\fR'.  However, exceptions are always thrown of the \f(CW\*(C`File\*(C'\fR
type, regardless of the capitalisation of the plugin named used.
.PP
.Vb 2
\&    [% USE file(\*(Aqfoo.html\*(Aq) %]
\&    [% file.mtime %]
.Ve
.PP
As with any other Template Toolkit plugin, an alternate name can be
specified for the object created.
.PP
.Vb 2
\&    [% USE foo = file(\*(Aqfoo.html\*(Aq) %]
\&    [% foo.mtime %]
.Ve
.PP
The \f(CW\*(C`nostat\*(C'\fR option can be specified to prevent the plugin constructor
from performing a \f(CW\*(C`stat()\*(C'\fR 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 \f(CW\*(C`stat()\*(C'\fR will be set
empty.
.PP
.Vb 2
\&    [% USE file(\*(Aq/some/where/over/the/rainbow.html\*(Aq, nostat=1)
\&    [% file.mtime %]     # nothing
.Ve
.SH "METHODS"
.IX Header "METHODS"
All \f(CW\*(C`File\*(C'\fR plugins, regardless of the \f(CW\*(C`nostat\*(C'\fR option, have set a number
of items relating to the original path specified.
.SS "path"
.IX Subsection "path"
The full, original file path specified to the constructor.
.PP
.Vb 2
\&    [% USE file(\*(Aq/foo/bar.html\*(Aq) %]
\&    [% file.path %]     # /foo/bar.html
.Ve
.SS "name"
.IX Subsection "name"
The name of the file without any leading directories.
.PP
.Vb 2
\&    [% USE file(\*(Aq/foo/bar.html\*(Aq) %]
\&    [% file.name %]     # bar.html
.Ve
.SS "dir"
.IX Subsection "dir"
The directory element of the path with the filename removed.
.PP
.Vb 2
\&    [% USE file(\*(Aq/foo/bar.html\*(Aq) %]
\&    [% file.name %]     # /foo
.Ve
.SS "ext"
.IX Subsection "ext"
The file extension, if any, appearing at the end of the path following
a '\f(CW\*(C`.\*(C'\fR' (not included in the extension).
.PP
.Vb 2
\&    [% USE file(\*(Aq/foo/bar.html\*(Aq) %]
\&    [% file.ext %]      # html
.Ve
.SS "home"
.IX Subsection "home"
This contains a string of the form '\f(CW\*(C`../..\*(C'\fR' to represent the upward path
from a file to its root directory.
.PP
.Vb 2
\&    [% USE file(\*(Aqbar.html\*(Aq) %]
\&    [% file.home %]     # nothing
\&
\&    [% USE file(\*(Aqfoo/bar.html\*(Aq) %]
\&    [% file.home %]     # ..
\&
\&    [% USE file(\*(Aqfoo/bar/baz.html\*(Aq) %]
\&    [% file.home %]     # ../..
.Ve
.SS "root"
.IX Subsection "root"
The \f(CW\*(C`root\*(C'\fR item can be specified as a constructor argument, indicating
a root directory in which the named file resides.  This is otherwise
set empty.
.PP
.Vb 2
\&    [% USE file(\*(Aqfoo/bar.html\*(Aq, root=\*(Aq/tmp\*(Aq) %]
\&    [% file.root %]     # /tmp
.Ve
.SS "abs"
.IX Subsection "abs"
This returns the absolute file path by constructing a path from the
\&\f(CW\*(C`root\*(C'\fR and \f(CW\*(C`path\*(C'\fR options.
.PP
.Vb 4
\&    [% USE file(\*(Aqfoo/bar.html\*(Aq, root=\*(Aq/tmp\*(Aq) %]
\&    [% file.path %]     # foo/bar.html
\&    [% file.root %]     # /tmp
\&    [% file.abs %]      # /tmp/foo/bar.html
.Ve
.SS "rel(path)"
.IX Subsection "rel(path)"
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 '\f(CW\*(C`home\*(C'\fR'
item.
.PP
.Vb 2
\&    [% USE file(\*(Aqfoo/bar/baz.html\*(Aq) %]
\&    [% file.rel(\*(Aqwiz/waz.html\*(Aq) %]      # ../../wiz/waz.html
.Ve
.SH "EXAMPLES"
.IX Header "EXAMPLES"
.Vb 1
\&    [% USE file(\*(Aq/foo/bar/baz.html\*(Aq) %]
\&
\&    [% file.path  %]      # /foo/bar/baz.html
\&    [% file.dir   %]      # /foo/bar
\&    [% file.name  %]      # baz.html
\&    [% file.home  %]      # ../..
\&    [% file.root  %]      # \*(Aq\*(Aq
\&    [% file.abs   %]      # /foo/bar/baz.html
\&    [% file.ext   %]      # html
\&    [% file.mtime %]      # 987654321
\&    [% file.atime %]      # 987654321
\&    [% file.uid   %]      # 500
\&    [% file.user  %]      # abw
\&
\&    [% USE file(\*(Aqfoo.html\*(Aq) %]
\&
\&    [% file.path %]           # foo.html
\&    [% file.dir  %]       # \*(Aq\*(Aq
\&    [% file.name %]           # foo.html
\&    [% file.root %]       # \*(Aq\*(Aq
\&    [% file.home %]       # \*(Aq\*(Aq
\&    [% file.abs  %]       # foo.html
\&
\&    [% USE file(\*(Aqfoo/bar/baz.html\*(Aq) %]
\&
\&    [% file.path %]           # foo/bar/baz.html
\&    [% file.dir  %]       # foo/bar
\&    [% file.name %]           # baz.html
\&    [% file.root %]       # \*(Aq\*(Aq
\&    [% file.home %]       # ../..
\&    [% file.abs  %]       # foo/bar/baz.html
\&
\&    [% USE file(\*(Aqfoo/bar/baz.html\*(Aq, root=\*(Aq/tmp\*(Aq) %]
\&
\&    [% file.path %]           # foo/bar/baz.html
\&    [% file.dir  %]       # foo/bar
\&    [% file.name %]           # baz.html
\&    [% file.root %]       # /tmp
\&    [% file.home %]       # ../..
\&    [% file.abs  %]       # /tmp/foo/bar/baz.html
\&
\&    # calculate other file paths relative to this file and its root
\&    [% USE file(\*(Aqfoo/bar/baz.html\*(Aq, root => \*(Aq/tmp/tt2\*(Aq) %]
\&
\&    [% file.path(\*(Aqbaz/qux.html\*(Aq) %]         # ../../baz/qux.html
\&    [% file.dir(\*(Aqwiz/woz.html\*(Aq)  %]     # ../../wiz/woz.html
.Ve
.SH "AUTHORS"
.IX Header "AUTHORS"
Michael Stevens wrote the original \f(CW\*(C`Directory\*(C'\fR plugin on which this is based.
Andy Wardley split it into separate \f(CW\*(C`File\*(C'\fR and \f(CW\*(C`Directory\*(C'\fR plugins, added
some extra code and documentation for \f(CW\*(C`VIEW\*(C'\fR support, and made a few other
minor tweaks.
.SH "COPYRIGHT"
.IX Header "COPYRIGHT"
Copyright 2000\-2022 Michael Stevens, Andy Wardley.
.PP
This module is free software; you can redistribute it and/or
modify it under the same terms as Perl itself.
.SH "SEE ALSO"
.IX Header "SEE ALSO"
Template::Plugin, Template::Plugin::Directory, Template::View

Zerion Mini Shell 1.0