NAME

App::FuguWeb::Config - the site description over Fugu::Config

SYNOPSIS

use App::FuguWeb::Config;

my $config = App::FuguWeb::Config->load(error => \my $reason)
    or die "$reason\n";

say $config->site;
say $_->{href} for $config->nav;
say $_->{file} for $config->pages;

DESCRIPTION

The class reads .fuguwebrc, applies the defaults, and validates the result. The grammar, the quoting, and the yes/no spellings come from Fugu::Config; this class holds what is true of a site.

The object is immutable once loaded, and the module keeps no package state. Two sites in one process therefore share nothing.

METHODS

load

App::FuguWeb::Config->load(
    root  => $dir,          # default: discover
    error => \my $reason,
)

Read and validate the description. The method returns the object, or undef with the reason in $reason.

Without root, the method walks up from the working directory to the first directory that holds .fuguwebrc, as fuguvm finds .fuguvmrc.

The reason travels through a reference because the object that would hold it does not exist when the load fails.

A load fails when the file is absent, when a line does not parse, or when the description would make the build do something it must not. Every message names the file, and the block when a block is at fault.

The description is rejected when:

  • there is no site setting;

  • a page block names no source, or more than one;

  • two page blocks name the same file, or two manuals would become the same page;

  • a nav block has no label;

  • a path setting steps out of the project with a .. component;

  • a page block name is absolute or steps out of the output directory: the name becomes a file there, so it is a path and gets the same guard the sources get;

  • a manuals namespace holds a path separator: it prefixes a manual name, and that name becomes both the staged file and the published page;

  • a modules directory is not below module_root, which would leave the module with no name to take but its whole path;

  • a yes/no setting holds something that is neither;

  • the source directory holds a symlink. Every file there that the build does not render is copied into the site, so a symlink would publish whatever it points at, from anywhere on the machine.

A keys block adds its own rules. The description is rejected when:

  • two keys blocks name one directory, or one org word, or a key block stands with no keys block;

  • the keys block names no org, or an org that no key name can hold;

  • the keys name is not one segment below the source directory, names a directory of the path, names the staging directory of the build, or names a file that the site already holds;

  • the keys block names a contact without an expires, or the other way round, or an expires that RFC 3339 does not hold;

  • the keys block names a url that is not absolute;

  • the key directory holds no SHA256, no SHA256.sig, or a symlink;

  • a key block names no file, more than one file, or a setting that no block defines;

  • a key block names a status outside current, next and retired, or a second block declares the same key;

  • a key block names a setting that its type does not take: an email or a fingerprint on a signify key, and an email on a certificate;

  • an email is not a local part and a domain, or a fingerprint does not hold the width of its type. The fingerprint of an OpenPGP key holds 40 hexadecimal characters, and the SHA-256 of the DER of a certificate holds 64.

App::FuguWeb::Keys documents the blocks and the published tree.

root, path

The project root, and the .fuguwebrc that this object read.

source_path

my $dir  = $config->source_path;
my $file = $config->source_path('footer.body.html');

The source directory, or one file in it.

site, lang, out_dir, source_dir, entry, module_root, mandoc_os, man_url, stylesheet

The settings. site is the only one a project must give.

site            (required)  the name in the title of every page,
                            and the text of the header link
lang            en          the lang attribute of the document
out_dir         web/build   where the build writes
source_dir      web         the fragments and the assets
entry           index.html  the front page, and the header link
module_root     lib         the prefix a module name drops
                            (a trailing slash is dropped)
mandoc_os       OpenBSD     the mandoc -I os=, which pins the footer
man_url         https://man.openbsd.org/   where a remote .Xr goes
stylesheet      (searched)  the base stylesheet

stylesheet overrides the search that "share_path" in Fugu::File does. The search finds the sheet in a checkout and in an installed App-FuguWeb distribution alike, so most projects never set it.

The pod2man --center and --release values are not settings. They are constants of App::FuguWeb::Render: they pin the pod2man output so the site does not vary with the build host.

The navigation, in file order. Each entry is a hashref with href and label.

pages

The pages, in file order. Each entry is a hashref:

file        the name of the page in the output
title       the title, which defaults to the file name
source      one of body, markdown or index
value       what the source names, and undef for index
unlinked    true when no other page links to it

groups

The manual groups, in file order. Each entry is an App::FuguWeb::Config::Group, and the two block types interleave as the description wrote them.

inventory

Every path that the output directory must hold after a build: the pages of the description, one page for each manual of each group, the stylesheet, the assets, and each key directory. The build and the checks read the same list, so the two can never disagree about what the site holds.

A site is one flat directory, so most of the list holds file names. A key directory is one part below the root, so its entries hold a solidus.

keys_dirs

The name of each key directory, in file order. The list is empty when the description holds no keys block, so it is the test for one.

A description can hold several keys blocks, and each one names one directory. Each directory holds its own root of trust, per D-02, and a binding never crosses a directory. Two blocks must not name one directory.

keys_org, keys_contact, keys_expires, keys_url

my $org = $config->keys_org('keys');

The settings of one keys block. Each accessor takes the name of the directory, and each one answers undef for a name that no block holds.

keys_org     (required)  the first field of every key name
keys_contact             the Contact field of security.txt
keys_expires             the Expires field of security.txt
keys_url                 the published prefix of the directory,
                         with no trailing slash

RFC 9116 makes Contact and Expires both necessary, so contact and expires stand or fall together. The Encryption field needs an absolute URL, so a block that names no url writes no such field.

A site publishes one security.txt, so one block alone names the contact and the expiry. A second block that names either one fails the load.

keys_path

my $dir  = $config->keys_path('keys');
my $file = $config->keys_path( 'keys', 'SHA256' );

One source key directory, or one file in it. The method answers undef for a name that no keys block holds.

site_keys

my @key = $config->site_keys('keys');

The key blocks of one key directory, in file order. The directory that holds the file owns the block, as the extension of that file owns the type. A stem that two directories hold fails the load.

Each entry is a hashref:

name         the key file in the directory
stem         the block name, which is the name without the
             extension
type         signify, openpgp or x509, from the extension
serial       the rotation count of the purpose
purpose      what the key signs
status       current, next or retired
since        the date the key took its status, or undef
until        the date it left it, or undef
email        the address of an OpenPGP key, or undef
wkd          the Web Key Directory hash of that address
fingerprint  the declared fingerprint, in upper case, or undef

The list is named site_keys and not keys, because a method named keys in the package makes every call of the builtin ambiguous.

site_bindings

my @binding = $config->site_bindings('keys');

The binding files of one key directory, in name order. A binding is the signature of one key file by another key of the same directory. Each entry is a hashref:

name     the binding file in the directory
target   the key file that the signature covers
signer   the key file of the key that signed it
type     the type of the signer

A binding carries no block: its name holds every field, and Fugu::KeyDir parses it. The list holds a binding whose target and whose signer are both keys of that directory, and App::FuguWeb::Keys reports every other name as a stray file.

key_paths

Every path of every key directory in the output, relative to the output directory, or the empty list when the description holds no keys block. "inventory" holds the same paths.

The site holds one well-known tree, and each directory writes into it. The list therefore holds one entry for the policy file, and one for an address that two directories name.

GROUPS

A manuals or modules block becomes one group. A group never holds a list of manuals: it reads its directory, so a manual that is added reaches the site with no edit anywhere.

A group whose directory does not exist fails the load and names the directory. A silent empty group hides a typo in a path, and a rename that nothing catches is what this file exists to prevent.

kind, heading, anchor, namespace

kind is manuals or modules. heading is the block name, which becomes the <h2>, and anchor its id.

manuals

The manuals of the group, in the order the index shows them, as App::FuguWeb::Manual objects. The method reads the directory once and keeps the answer.

A manuals group reads its directory for *.1, *.3p, *.5, *.7 and *.8, and takes a plain file only. It does not glob: Perl's glob splits its pattern on whitespace and reads [ ] { } ? ~, so a project whose path holds one of them would lose its manuals or collect a sibling directory's. It sorts by section, in the order 1, 3p, 5, 7, 8, and then by file name. The namespace setting prefixes the name and the staged file name, so man/fugu/Daemon.3p becomes Fugu::Daemon(3p).

A modules group finds every .pod file below its directory, and the sidecar that names the directory itself: lib/App/FuguWeb.pod is the umbrella of lib/App/FuguWeb/. It sorts by path, so Store.pod stays before Store/Memory.pod.

Both sorts compare bytes and never read the locale of the builder. A site must not depend on the machine that built it.

Never name a directory that holds more than one namespace. In this repository lib/App is such a directory, and one group there would swallow three namespaces.

SEE ALSO

App::FuguWeb, App::FuguWeb::Keys, App::FuguWeb::Manual, Fugu::Config, fuguweb(1)

AUTHOR

Dick Olsson <hi@senzilla.io>