Wikifier::Page

Wikifier::Page is a programming interface for working with a single wiki page or article.

Constructor

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, name is required)

  • name - optional, page file basename (if not specified, file_path is required; basename of file_path is 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_path is required and will be read and parsed instead

parse

my $err = $page->parse;
die "Failed to parse page: $err\\n";

Parses the page, returning an error on failure, otherwise nothing.

html

my $html = $page->html;

Generates and returns HTML for the page. ->parse MUST be called before this.

css

Generates and returns CSS for the page. ->html MUST be called before this.

set

$page->set(my_var => 'some value');

Assigns a value to a page variable.

get

my $val = $page->get('my_var');

Fetches the value of a page variable. Returns undef if nothing exists there.

parse_formatted_text

my $text = 'Hello, [b]World[/b]!';
say $page->parse_formatted_text($text); # "Hello, <b>World</b>!"

Translates wiki formatting codes to HTML.

opt

say "Welcome to ", $page->opt('name'); # "Welcome to My Wiki!"

Fetches a wiki configuration option.

page_opt

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.

name

$page->name     # "some_page.page"

Name of the page including the file extension.

name_ne

$page->name_ne  # "some_page"

Name of the page without the file extension.

prefix

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

rel_name

$page->rel_name

Returns the page name relative to the page directory. Unlike ->name, this does not take redirects/symlinks into account.

rel_name_ne

$page->rel_name_ne

Like rel_name, except without the file extension.

rel_path

$page->rel_path

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

redirect

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.

path

$page->path

Absolute path to the page file.

created

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

modified

$page->modified

UNIX timestamp at which the page file was last modified as reported by the filesystem.

cache_path

$page->cache_path

Absolute path to the page cache file which may or may not exist.

cache_modified

$page->cache_modified

UNIX timestamp at which the page cache file was last modified as reported by the filesystem.

search_path

$page->search_path

Absolute path to the plaintext page search file which may or may not exist.

draft

$page->draft

True if the page is marked as a draft by the special @page.draft variable.

generated

$page->generated

True if the page is marked as autogenerated by the special @page.generated variable.

author

$page->author

Author of the page, as specified by the special @page.author variable. Returns undef if the author is unspecified.

fmt_title

$page->fmt_title

HTML-formatted page title.

title

$page->title

Like fmt_title, except HTML tags have been stripped.

title_or_name

$page->title_or_name

Returns the page title if available, without HTML formatting; otherwise the page filename.

pos

$page->pos

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

warning

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

$page->page_info

Returns a hash reference of page metadata suitable for JSON serialization.