Prima::...le::Pod(3)
πΈ NAME πΈ
Prima::Drawable::Pod β it's a POD parser and a renderer, bestie. Both. Multi-talented. π
β¨ SYNOPSIS β¨
use Prima::Drawable::Pod;
use Prima::PS::Printer;
my $pod = Prima::Drawable::Pod->new;
$pod-> load_pod_content("=head1 NAME\n\nI'm also a pod!\n\n");
my $printer = Prima::PS::PDF::File->new( file => 'pod.pdf');
$printer-> begin_doc or die $@;
$pod-> print($printer);
$printer-> end_doc;
π¦ DESCRIPTION π¦
okay so Prima::Drawable::Pod literally contains a formatter (in the perlpod sense, iykyk) and a renderer for POD content. The POD text gets converted into a model β a set of text blocks in the format described over in Prima::Drawable::TextBlock. π
But here's the tea: those model blocks are not directly usable. Nope. They need to be rendered into another set of text blocks, and those are the ones you can actually draw on the screen, a printer, whatever. The module also hands you helper routines for all of this. π«Ά
π USAGE π
The package is made of several logically separated parts, which lowkey slay: file locating and loading, formatting, and navigation. π
π Content methods
load_pod_content CONTENT, %OPTIONSβ the high-level POD content parser. The%OPTIONSare the same ones as inopen_read. β¨open_read %OPTIONSβ clears whatever content you had and enters reading mode. In this mode you can keep appending content by calling thereadmethod over and over, which pushes the raw POD content into the parser. π₯read TEXTβ feeds theTEXTstring to the parser. It parses basic indentation, but the main formatting happens insideaddandadd_formatted.
fr fr, this must only be called inside theopen_read/close_readbrackets. π
add TEXT, STYLE, INDENTβ formats theTEXTstring using the givenSTYLE(which is one of thepod::STYLE_XXXconstants) withINDENTspaces.
same deal, bestie: only within theopen_read/close_readbrackets. π
add_formatted FORMAT, TEXTβ adds a pre-formattedTEXTwith a givenFORMAT, supplied by the=beginor=forPOD directives.Prima::PodViewunderstands the'text'and'podview'FORMATs. That'podview'format is forPrima::PodViewitself and contains a small number of commands for rendering images in documents. πΌοΈ
The 'podview' commands are:
β cut
Example:
=for podview <cut>
=for text just text-formatter info
....
text-only info
...
=for podview </cut>
The <cut> clause skips all POD input until it's canceled. It's used together with the following command, img, so a POD manpage can serve up both graphic content ('podview', 'html', etc.) and text content ('text'). πβ¨
β img [src="SRC"] [width="WIDTH"] [height="HEIGHT"] [cut="CUT"] [frame="FRAME"]
An image inclusion command, where src is a relative or absolute path to an image file. If you need scaling, you can set the width and height options. If the image is a multiframe image, you can set the frame index with the frame option. And there's a special cut option β if it's set to a true value, it activates the cut behavior if (and only if) the image load operation is unsuccessful. This makes simultaneous use of 'podview' and 'text' possible:
=for podview <img src="graphic.gif" cut=1 >
=begin text
y .
| .
|.
+----- x
=end text
=for podview </cut>
In the example above, 'graphic.gif' will be shown if it can be found and loaded β otherwise the poor-man drawings get selected. ππ¨
If src is omitted, the image is retrieved from the images array, from the index frame.
It's also possible to embed images directly in the pod, by using a special src tag for base64-encoded images. The format should preferably be GIF, since that's Prima's default format, or BMP for very small images, since it's supported without third-party libraries:
=for podview <img src="data:base64">
R0lGODdhAQABAIAAAAAAAAAAACwAAAAAAQABAIAAAAAAAAACAkQBADs=
β close_read
Closes the reading mode. Returns undef if there's no POD context, otherwise a hash with topic_id (the ID of the first topic containing the content) and the success flag. π
ποΈ Topics
Topics live in the {topics} array, where each one is an array with the following indices of the pod::T_XXX constants:
pod::T_MODEL_START - start of topic
pod::T_MODEL_END - end of a topic
pod::T_DESCRIPTION - topic name
pod::T_STYLE - pod::STYLE_XXX constant
pod::T_ITEM_DEPTH - depth of =item recursion
pod::T_LINK_OFFSET - offset in the links array
π¨ Styles
The ::styles property gives you access to the styles applied to different pod text parts. These styles are:
pod::STYLE_CODE - style for C<>
pod::STYLE_TEXT - normal text
pod::STYLE_HEAD_1 - =head1
pod::STYLE_HEAD_2 - =head2
pod::STYLE_HEAD_3 - =head3
pod::STYLE_HEAD_4 - =head4
pod::STYLE_HEAD_5 - =head5
pod::STYLE_HEAD_6 - =head6
pod::STYLE_ITEM - =item
pod::STYLE_LINK - style for L<> text
pod::STYLE_VERBATIM - style for pre-formatted text
Each style is a hash with the keys fontId, fontSize, fontStyle, color, and backColor β fully analogous to the tb::BLK_DATA_XXX options. This functionality gives you another layer of accessibility to the pod formatter. π¦
π¨οΈ Rendering
The model loaded by the read functions is stored internally. It does not care about screen resolution, fonts, colors, etc. β it's independent, main character energy. To render or print it, use these functions:
begin_format %OPTIONSβ starts a formatting session. The following options are recognized:allow_width_overrun BOOLEAN=1β if set, allows the resulting block width to overrun the canvas width. If set, you can query the actual width by calling theaccumulated_width_overrunmethod. Otherwise it forcibly breaks blocks that are explicitly marked to be not wrapped.colormap ARRAYβ an array of at least 5 color entries (default foreground color, default background color, link color, verbatime text color, and its background color). If unset, some sensible default values are used.fontmap ARRAY_OF_HASHESβ a set of at least 2 hashes, each describing a font to be used for normal text (index0) and verbatim text (index1). If unset, some sensible default values are used.hmargin,vmarginβ target device marginsresolution ARRAY_OF_2β target device resolutionwidth,heightβ target device size
format_model $MODELβ renders a model block$MODELand returns zero or more text blocks suitable for drawing on the given canvas. Theblock_drawmethod can be used for the same purpose too. πend_formatβ ends the formatting session.
π¨οΈ Printing
The print method prints the pod content on a target canvas. It accepts the following options (along with all the other options from begin_format):
canvas OBJECTβ the target devicefrom,to INDEXβ selects the model range to be printed
π¦ Block export
The export_blocks method can render the model into a set of blocks that can be reused elsewhere. This functionality is used by Prima::Label, which is able to display the pod content. It returns a Prima::Drawable::PolyTextBlock object β a super-set of text blocks that also contains all the necessary information (fonts, colors, etc.) needed to pass on the block drawing routines and to be suitable as input for the text_out method. π
The method accepts the following options (along with all the other options from begin_format):
canvas OBJECTβ the target devicefrom,to INDEXβ selects the model range to be printedmax_height INTEGERβ stops rendering aftermax_heightpixels are occupied by the pod contenttrim_header BOOLEANβ if set, removes the topic or page header, so that only the content itself is renderedtrim_footer BOOLEANβ prunes empty newlineswidth INTEGERβ desired render width in pixels
π§ Navigation
load_link LINK, %OPTIONSβ parses and loads POD content fromLINK. If theLINKcontains a section reference, it loads only that section. Returns the success flag. The%OPTIONSare the same as understood byload_pod_fileandopen_read. πload_pod_file FILE, %OPTIONSβ the high-level POD file reader. The%OPTIONSare the same as inopen_read.parse_link LINKβ accepts text in the format of a perlpodL<>link:manpage/section. Returns a hash with up to two items,fileandtopic. Iffileis set, then the link contains a file reference. Iftopicis set, then the link topic matches the currently loaded set of topics. π
note: if the requested file isn't loaded β f.ex. byload_pod_fileβ thentopicwill not be matched. Issue another call toparse_linkto match the topic iffileis set. iykyk π
π SEE ALSO π
Prima::Drawable::TextBlock, Prima::PodView.
π«Ά AUTHOR π«Ά
Dmitry Karasik, <dmitry@karasik.eu.org>.
π and that's the whole page, bestie β this was Prima::Drawable::Pod, page Prima::...le::Pod(3), from perl v5.42.0, dated 2024-08-20. slay, go read some POD β¨ππ
π¦ where this page comes from
- opensuse-leap 16.0: perl-Prima 1.74000-bp160.1.13 Β· AGPL-3.0-only AND BSD-2-Clause
- opensuse-leap 16.0: perl-Prima 1.74000-bp160.1.13 Β· AGPL-3.0-only AND BSD-2-Clause
- opensuse-leap 16.0: perl-Prima 1.74000-bp160.1.13 Β· AGPL-3.0-only AND BSD-2-Clause
- opensuse-leap 16.0: perl-Prima 1.74000-bp160.1.13 Β· AGPL-3.0-only AND BSD-2-Clause
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms