Zim::Page.3pm

Langue: en

Autres versions - même langue

Version: 2009-02-23 (debian - 07/07/09)

Section: 3 (Bibliothèques de fonctions)

NAME

Zim::Page - Page object for Zim

DESCRIPTION

This class defines a page object. A page is the unit of data as presented to the user. The source of the data is managed by Zim::Store objects.

OVERLOAD

This class overloads the '""' operator, so the string version of an object is the page name.

METHODS

"new(PARENT, NAME)"
Simple constructor. PARENT should be a repository object of class Zim. NAME is the page name for this object.
"properties()"
Returns a hash with properties. See ``PROPERTIES''.
"name()"
Get or set the full name of the page.
"basename()"
Returns the last part of the page name.
"split_name()"
"namespace()"
Returns the namespace to which this page belongs.
"namespaces()"
Like "namespace()" but returns the namespace path as a list.
"status(STRING)"
Set or get a status string for this page. Typical status strings are 'new' and 'deleted'.
"exists()"
Returns TRUE if the page already exists.
"copy(TARGET, UPDATE_LINKS)"
"move(TARGET, UPDATE_LINKS)"
"delete()"
The methods "copy()", "move()" and "delete()" are aliases for the methods "copy_page()", "move_page()" and "delete_page()" in the public store interface; see Zim::Store.

TARGET is the new name for the page. The UPDATE_LINKS argument is a boolean that tells whether links to this page should be updated to point to this new name.

"parse_link(LINK, NO_RESOLVE)"
Returns a link type and a link target, see Zim::Formats.
"resolve_page(NAME, NO_DEFAULT)"
Caching wrapper for "$repository-"resolve_page(NAME, PAGE, NO_DEFAULT)>.
"resolve_name(NAME, NO_DEFAULT)"
Caching wrapper for "$repository-"resolve_name(NAME, PAGE, NO_DEFAULT)>.
"match_word(WORD)"
TODO: stable api for this
"equals(PAGE)"
Check if PAGE is refering to the same page we are. This does not guarantee that the actual content is the same.
"clone(PAGE, media =" MEDIA, doc_root => PREFIX)>
Import content from page object PAGE into this object. PAGE typically belongs to a different notebook. Deletes current contents.

MEDIA can be 'none', 'default' or 'all'. When 'none' is set no media is copied. When 'default' is set all files below the document dir root are copied. For 'all' we automatically attach external files.

PREFIX is a prefix we use for links under the document root. If this is set any files under the document root will not be copied for any setting of MEDIA.

"get_next()"
Returns next page.
"get_prev()"
Return previous page.

Source Interface

"set_source(SOURCE)"
SOURCE is an object that supports an "open(MODE)" method, which returns a filehandle (or IO object) for the source, and an "exists()" method which checks if there is anything to open.

If SOURCE is "undef" this unsets the source, making the page read-only.

This method sets the 'read_only' property depending on whether SOURCE is defined or not.

"open_source(MODE)"
Returns an IO object or undef when there is none. This method dies when it fails opening a given source. In general pages that have status ``new'' will not yet have a source.

MODE is optional and can either be 'r' or 'w' depending on whether you would like the source to be opened for reading or for writing.

Do not forget to close the IO object when you are done with it ! Use OO syntax to close it, using "$fh->close" instead of "close $fh".

"has_source()"
Returns a boolean.

Formatted Interface

"set_format(FORMAT)"
Sets a source format for this page. This can either be an object of the class Zim::Formats (or similar), or a name in which case this will be looked up in the "Zim::Formats::*" namespace.

Formats are only used for pages that also have a source object.

"get_parse_tree()"
Get the parse tree for this page.

When using source this method will return the tree resulting from running the given source through the given formatter.

"set_parse_tree(TREE)"
Set the parse tree for this page. Will fail when the page is read-only.

When using source this method will use the formatter to save the parse tree to the IO object.

"list_links()"
Returns a list with names of pages that this page links to.
"list_backlinks()"
Returns a list with names of pages that link to this page.
"update_links(FROM =" TO, ...)>
Update links to other pages. This is used for example when a page is moved to update all links to that page.
"update_links_self(OLD)"
Called if the current page was moved from OLD to current name. Updates links to reflect this move.

Document Interface

These methods are used to store and retrieve documents. This has nothing to do with the source of the page, these documents should be regarded as attachments.

See detailed documentation in Zim::Store.

"document_dir()"
"store_file(FILE, NAME, MOVE)"
"resolve_file(PATH)"
"relative_path(FILE)"

Other Functions

"relative_name(NAME)"
Turns an absolute page name into one that is relative to this page. Reverses part of the logic of "resolve_name()". Returns either relative or absolute name.
"get_text()"
Returns plain text page. Used by ``Email Page'' action. Not to be used for exporting.
"commit_change()"
"discard_change()"

PROPERTIES

The page object contains a hash with properties. These can be any kind of data from the backend that needs to be shared with the interface. Typically it are config options that can be specified per-page.

For the ``formatted'' page interface the properties hash is used for the Document meta attributes in the parse-tree.

Common properties are:

base (url)
Base directory for files that belong to this page in some way or another. This is for example used by the interface to resolve the location of image files that are included in the page.

This value can be undefined when the store does not allow direct access to the source files.

TODO: At the moment this is the directory which contains the page file, this is open for change in future versions.

Currently only the "file://" url is really supported.

read_only (boolean)
Tells the interface that this page should not be edited. Defaults to TRUE.
special (boolean)
Rare cases a non-existent read_only page is used to display some information or because there is simply nothing else to display. This property makes various components ignore these pages. For example they don't show up in the history.

AUTHOR

Jaap Karssenberg (Pardus) <pardus@cpan.org>

Copyright (c) 2005 Jaap G Karssenberg. All rights reserved. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.

SEE ALSO

Zim, Zim::Store