Para::Frame::File - Represents a file in the site
See also Para::Frame::Dir and Para::Frame::Template.
The same file used in two sites will be represented two times.
TODO: Separate out sysfile from sitefile.
Para::Frame::File->new( $params )
Creates a File object. It should be initiated before used. (Done by the methods here.)
params:
hide req filename url site file_may_not_exist
$f->site( $def_site )
Checks if the templates this has been compiled from has changed.
Depends on the info given by /set_depends_on
Prefix url_ gives the path of the dir in http on the host
Prefix sys_ gives the path of the dir in the filesystem
No prefix gives the path of the dir relative the site root in url_path
path_base excludes the suffix of the filename
path gives the preffered URL for the file
For dirs: always exclude the trailing slash, except for path_slash
Same as /dir, except that if the template is the index, we will instead get the parent dir.
$f->dir() $f->dir( \%params )
Gets the directory for the file.
Returns self if file is a directory.
See also Para::Frame::Dir/parent
params:
none
Returns
May not return a dir. It may be another type of file in the case then this file was hypothetical.
The URL path to the template, excluding the filename, relative the site home, begining but not ending with a slash. May be an empty string.
The template filename without the path.
For dirs, the dir name without the path and without trailing slash.
The template filename without the path.
For dirs, the dir name without the path but with the trailing slash.
$f->path( $def_site )
The preffered URL for the file, relative the site home, begining with a slash. And for dirs, not ending with a slash.
The preffered URL for the file, relative the site home, begining with a slash. And for dirs, ending with a slash.
$f->set_site( $site )
Sets the site to use for this request.
$site
should be the name of a registred Para::Frame::Site or a
site object.
The site must use the same host as the request.
The method works similarly to Para::Frame::Request/set_site
Returns: The site object
The path from the system root. Excluding the last '/' for dirs.
The path from the system root. Including the last '/' for dirs.
The path to the template from the system root, including the filename. But excluding the suffixes of the file along with the dots. For Dirs, excluding the trailing slash.
Returns the URI object, including the scheme, host and port.
Returns the URI object, including the scheme, host, port and query string.
The URL for the file in http on the host. For dirs, excluding trailing slash.
This is the PREFERRED URL for the file in http on the host. For dirs, including trailing slash.
$file->jump( $label, \%attrs )
The path to the template, including the filename, relative the site home, begining with a slash. But excluding the suffixes of the file along with the dots.
Not valid for dirs
The filename, but excluding the last suffix and the preceeding
language suffix, if existing, along with the dots. For Dirs, excluding
the trailing slash. Be careful since this will return an empty string
for hidden files like .htaccess
.
Not valid for dirs
The suffix (extension) part of the file, exclusive the dot.
Returns the last part as a string. The file /index.sv.tt
will
return tt
.
For dirs or for files without a suffix, we will return '';
$f->chmod() $f->chmod( $mode, \%args )
Calls Para::Frame::Utils/chmod_file
$file->vcs_version()
VCS stands for Version Control System.
Gets the current version string of this file.
May support other systems than CVS.
Returns: the scalar string
$file->filesize()
Returns: the filesize in human readable format
The corresponding template URL for this file. This will give
/index.en.tt
for /
.
It may not be cached between requests since the language may change.
args:
lang_code language
$f->template()
For finding the template to use for rendering the URL of $f
.
Uses dirconfig find
or Para::Frame::Site/find_class.
Returns:
A Para::Frame::Template object or undef
Removes language parts and index.tt
from URLs.
$f->normalize()
If that changes the URL, returns a new Para::Frame::File object,
with the flag may_not_exist
.
Returns a ref to a scalar with the content of the file
Returns the content of the file
Detects the charset and decodes to UTF8
Returns a ref to a scalar with the content of the file
Detects the charset and decodes to UTF8
Returns a ref to a scalar with the content of the file
Detects the charset and decodes to UTF8
Returns a string with the contnet of the file, formatted as html, with style and links
$file1->copy( $file2 )
$file->exist()
Stats the file and returns true or false
$f->is_compiled( $def_site )
$file->mtime()
Returns a Para::Frame::Time object based on the files mtime.
This will update the object if mtime has changed.
This will update the object if mtime has changed.
See perl utime
$f->renderer( \%args )
For getting the renderer used for a request response, see Para::Frame::Request::Response/renderer.
The default renderer is Para::Frame::Renderer::TT.
Any %args
are given to the renderer constructor -- usually
Para::Frame::Renderer::TT/new.
The page
arg is always set to $f.
Returns a new renderer object each time it is called.
$f->dirsteps
Returns: the current dirsteps as a ref to a list of strings.
Returns the number of files removed (1)
$f->as_dir
This should be a dir. Make it so if it isn't.
Returns: the object
This should be a Template. Make it so if it isn't.
Returns the file as a template object
$f->set_content_as_text( \$data )
Updates the file content and saves it in the file, in UTF8, starting with a UTF8 BOM.
TODO: Convert CRLF to LF?
\$data
shoule be a reference to a scalar containing the new content
of the file.
Returns: true on success
$f->set_content( \$data )
Updates the file content and saves it in the file.
\$data
shoule be a reference to a scalar containing the new content
of the file.
Returns: true on success
$dest->precompile( \%args )
$dest
is the file resulting from the compilation. It's the
place there the precompiled file should be saved. You may get the
$dest
from a Para::Frame::Dir/get_virtual and it should be a
(virual) file recognized as a template, for example by givin it a
.tt
file suffix.
The template to be used for the construction of this file is given
by the arg template
.
Send same args as for /new for creating the new page from thre
source $page
. Also takes:
arg template arg type defaults to html_pre arg umask defaults to 02 arg params arg template_root arg charset
The $dest
is normalized with Para::Frame::File/normalize. It's
this normalized page that is rendered. That will be the object
availible in the template during rendering as the page
variable
(both during the precompile and during later renderings).
The args template
and template_root
is given to
Para::Frame::Renderer::TT/new via Para::Frame::File/renderer.
Returns: $dest