NAME

Para::Frame::File - Represents a file in the site

DESCRIPTION

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.

new

  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

reset

new_sysfile

new_possible_sysfile

site

  $f->site( $def_site )

req

initiate

set_depends_on

is_updated

Checks if the templates this has been compiled from has changed.

Depends on the info given by /set_depends_on

initialize

Accessors

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

parent

Same as /dir, except that if the template is the index, we will instead get the parent dir.

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.

A Para::Frame::Dir

dir_url_path

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.

name

The template filename without the path.

For dirs, the dir name without the path and without trailing slash.

name_slash

The template filename without the path.

For dirs, the dir name without the path but with the trailing slash.

path

  $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.

path_slash

The preffered URL for the file, relative the site home, begining with a slash. And for dirs, ending with a slash.

set_site

  $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

sys_path

The path from the system root. Excluding the last '/' for dirs.

sys_path_slash

The path from the system root. Including the last '/' for dirs.

sys_base

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.

url

Returns the URI object, including the scheme, host and port.

url_with_query

Returns the URI object, including the scheme, host, port and query string.

url_path

The URL for the file in http on the host. For dirs, excluding trailing slash.

url_path_slash

This is the PREFERRED URL for the file in http on the host. For dirs, including trailing slash.

jump

  $file->jump( $label, \%attrs )

base

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

base_name

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

suffix

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 '';

langcode

chmod

  $f->chmod()

  $f->chmod( $mode, \%args )

Calls Para::Frame::Utils/chmod_file

vcs_version

  $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

filesize

  $file->filesize()

Returns: the filesize in human readable format

desig

sysdesig

target

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

target_with_lang

target_without_lang

template

  $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

normalize

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.

contentref

Returns a ref to a scalar with the content of the file

content

Returns the content of the file

content_as_text

Detects the charset and decodes to UTF8

Returns a ref to a scalar with the content of the file

content_as_text

Detects the charset and decodes to UTF8

Returns a ref to a scalar with the content of the file

content_as_html

Detects the charset and decodes to UTF8

Returns a string with the contnet of the file, formatted as html, with style and links

copy

  $file1->copy( $file2 )

exist

  $file->exist()

Stats the file and returns true or false

is_template

is_dir

is_plain_file

is_image

is_readable

is_owned

is_compiled

  $f->is_compiled( $def_site )

mtime

  $file->mtime()

Returns a Para::Frame::Time object based on the files mtime.

This will update the object if mtime has changed.

mtime_as_epoch

This will update the object if mtime has changed.

utime

See perl utime

load_compiled

renderer

  $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.

dirsteps

  $f->dirsteps

Returns: the current dirsteps as a ref to a list of strings.

remove

Returns the number of files removed (1)

as_dir

  $f->as_dir

This should be a dir. Make it so if it isn't.

Returns: the object

as_template

This should be a Template. Make it so if it isn't.

Returns the file as a template object

mimetype

mimetype_base

set_content_as_text

  $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

set_content

  $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

precompile

  $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

SEE ALSO

Para::Frame