Wikifier::Page is a programming interface for working with a single wiki
page or article.
my $page = Wikifier::Page->new(%opts)Creates a new page object. The object may be associated with a page file. You
should only use this constructor if working with page objects independently of a
Wikifier::Wiki. Otherwise, use Wikifier::Wiki::page_named().
%opts - hash of options
- wikifier - optional, wikifier instance to reuse
- file_path - optional, page file path (if not specified,
nameis required) - name - optional, page file basename (if not specified,
file_pathis required; basename offile_pathis used as page name) - vars_only - optional, if true, only variables will be parsed, not page content
- source - optional, page source code written in the wikifier language.
if not provided, the file specified by
file_pathis required and will be read and parsed instead
my $err = $page->parse;
die "Failed to parse page: $err\n";Parses the page, returning an error on failure, otherwise nothing.
my $html = $page->html;Generates and returns HTML for the page. ->parse MUST be called
before this.
Generates and returns CSS for the page. ->html MUST be called before
this.
$page->set(my_var => 'some value');Assigns a value to a page variable.
my $val = $page->get('my_var');Fetches the value of a page variable. Returns undef if nothing exists there.
my $text = 'Hello, [b]World[/b]!';
say $page->parse_formatted_text($text); # "Hello, <b>World</b>!"Translates wiki formatting codes to HTML.
say "Welcome to ", $page->opt('name'); # "Welcome to My Wiki!"Fetches a wiki configuration option.
if ($page->page_opt('page.enable.title')) {
$show_title++;
}Like opt except it checks the page itself for the option before
consulting the wiki configuration.
$page->name # "some_page.page"Name of the page including the file extension.
$page->name_ne # "some_page"Name of the page without the file extension.
# assuming $page->name is "hello/world.page"
$page->prefix # "hello"Returns the page prefix; i.e. the subdirectory within the page directory at which this page exists. If the page is at root level, returns undef.
$page->rel_nameReturns the page name relative to the page directory. Unlike ->name,
this does not take redirects/symlinks into account.
$page->rel_name_neLike rel_name, except without the file extension.
$page->rel_pathReturns the relative path to the page. This is actually an absolute path, but
it is called relative because, unlike path, symlinks are not taken
into account.
if (length(my $redir = $page->redirect)) {
say "Redirecting to $redir";
}Location to which this page redirects. This may be a relative or absolute URL, suitable for use in a Location header. Returns undef if the page does not redirect.
$page->pathAbsolute path to the page file.
$page->created
UNIX timestamp of page creation, according to the
@page.created special variable. If the
variable is not defined or is not provided in an accepted format, returns a
false value.
$page->modifiedUNIX timestamp at which the page file was last modified as reported by the filesystem.
$page->cache_pathAbsolute path to the page cache file which may or may not exist.
$page->cache_modifiedUNIX timestamp at which the page cache file was last modified as reported by the filesystem.
$page->search_pathAbsolute path to the plaintext page search file which may or may not exist.
$page->draftTrue if the page is marked as a draft by the special
@page.draft variable.
$page->generatedTrue if the page is marked as autogenerated by the special
@page.generated variable.
$page->authorAuthor of the page, as specified by the special
@page.author variable. Returns undef if
the author is unspecified.
$page->fmt_titleHTML-formatted page title.
$page->titleLike fmt_title, except HTML tags have been stripped.
$page->title_or_nameReturns the page title if available, without HTML formatting; otherwise the page filename.
$page->posDuring parsing, returns the current position within the page. After parsing, this refers to the first line of the page file so that any possible improperly-positioned warnings are still visible.
$page->warning($pos, 'Something has gone wrong');Produces a page warning at the specified position. If the position argument
is omitted, the value of ->pos is used.
$page->page_infoReturns a hash reference of page metadata suitable for JSON serialization.