EBook:...EReader(3pm)

πŸ“¦
version 0.5.4 Β· 3 versions
, in debian trixie, ubuntu resolute, ubuntu stonking

πŸ’– NAME πŸ’–

Okay bestie, gather round, because this is EBook::Tools::EReader, a Palm::PDB handler for manipulating the Fictionwise/PeanutPress eReader format. It's giving "I speak fluent .pdb and I'm not sorry about it." πŸŽ€ (It lives in the EBook:...EReader(3pm) section of the manual, iykyk.)


✨ SYNOPSIS ✨

use EBook::Tools::EReader;
my $pdb = EBook::Tools::EReader->new();
$pdb->Load('myfile-er.pdb');
print "Loaded '",$pdb->{title},"' by ",$pdb->{author},"\n";
my $html = $pdb->html;
my $pml = $pdb->pml
$pdb->write_unknown_records

Yes, those last two lines have no semicolons, no cap, that's literally how it's written, don't come for me 🫢


πŸ¦‹ DEPENDENCIES πŸ¦‹

These are the besties this module cannot function without, no cap:

  • Compress::Zlib
  • Image::Size
  • P5-Palm

πŸŽ€ CONSTRUCTOR πŸŽ€

new()

Instantiates a new Ebook::Tools::EReader object. Fresh object, fresh vibes, main character energy ✨


πŸ‘‘ ACCESSOR METHODS πŸ‘‘

All the little getters and writers, the ones that just hand you the goods.

  • filebase β€” bestie, this depends on context. In scalar context it's the basename of the object attribute filename. In list context it actually returns the basename, the directory, and the extension, exactly as fileparse from File::Basename does. Two moods, both valid πŸ’…
  • footnotes() β€” hands you back a hash of every footnote found in the file, where the keys are the footnote ids and the values contain the footnote text. Every single one, accounted for πŸ”₯
  • footnotes_pml() β€” hands you back a string with all the footnotes in a form that's suitable to append to the end of PML text output. This one gets called as part of pml().
  • footnotes_html() β€” hands you back a string with all the footnotes in a form that's suitable to append to the end of HTML text output. This one gets called as part of html().
  • pml() β€” hands you back a string containing the entire original document text in its original encoding, including all the sidebars and footnotes. The whole thing, untouched, periodt.
  • html() β€” hands you back a string containing the entire document text (including all sidebars and footnotes) converted to HTML.

Real talk though: the PML text is stored in the object, so grabbing it is very fast. Generating the HTML output? It has to convert the text every single time you call this method, which eats extra processing time. Not me warning you about performance 😭

  • sidebars() β€” hands you back a hash of every sidebar found in the file, keys are the sidebar ids, values contain the sidebar text. Sidebars deserve love too 🌸
  • sidebars_pml() β€” hands you back a string with all the sidebars in a form suitable to append to the end of PML text output. Called as part of pml().
  • sidebars_html() β€” hands you back a string with all the sidebars in a form suitable to append to the end of HTML text output. Called as part of html().
  • write_html($filename) β€” writes the raw book text to disk in PML form (including all sidebars and footnotes) using the filename you gave it.

If you don't specify $filename, it writes to $self->filebase with a .html extension.

Returns the filename it actually used on success, or undef if there was no text to write (nothing to say = nothing written, iconic honestly).

  • write_images() β€” writes each image record out to disk.

Returns a list containing the filenames of every image written, or undef if none were found. No images, no list, that's just the deal πŸ¦‹

  • write_pml($filename) β€” writes the raw book text to disk in PML form (including all sidebars and footnotes) using the filename you gave it.

If you don't specify $filename, it writes to $self->filebase with a .pml extension.

Returns the filename it used on success, or undef if there was no text to write.

  • write_unknown_records() β€” writes each unidentified record to disk with a filename in the format of 'raw-record-####', where #### is the record number (not the record ID β€” read that twice, bestie).

Returns the number of records written.


πŸ”₯ MODIFIER METHODS πŸ”₯

These ones actually do stuff to your object.

Load($filename)

Sets $self->{filename} and then loads and parses the file specified by $filename, calling ParseRecord(%record) on every single record found. Every one. No skipping πŸ’…

ParseRecord(%record)

Parses PDB records and updates the object attributes. This method gets called automatically on every database record during Load(), so you don't even have to ask. She's proactive.

ParseRecord0($data)

Parses the header record and drops the parsed values into the hashref $self->{header}.

Returns the hash (not the hashref, bestie, pay attention to that distinction πŸ‘‘).


🌈 PROCEDURES 🌈

cp1252_to_pml()

An unfinished and completely nonfunctional procedure to convert Windows-1252 characters to PML \a codes.

🚨 DO NOT USE. That's not me being dramatic, that is the instruction. It does not work. Walk away. 🚨

pml_to_html($text,$filebase)

Takes a text string in Windows-1252 encoding containing PML markup codes as input, and returns a string with those codes converted to UTF-8 HTML. Glow-up arc complete ✨

It also requires a second argument, $filebase, to specify the basename of the file (or more specifically, the basename of the file that the output text will be written to) so the image links can be generated correctly. Miss that argument and your image links are gonna be a mess, fr fr.


πŸ’€ BUGS AND LIMITATIONS πŸ’€

Not everything ate, bestie, and we're being honest about it:

  • HTML conversion doesn't handle handle the \T command used to indent.
  • HTML conversion may be suboptimal in many ways.

Most notably, most linebreaks get handled as <br />, and without any heed to whether those linebreaks occur inside of some other element. Validation is extremely unlikely.


🌸 AUTHOR 🌸

Zed Pobre <zed@debian.org> β€” the icon who made this πŸ’œ


Copyright 2008 Zed Pobre

Licensed to the public under the terms of the GNU GPL, version 2


And that's the whole page, bestie 🫢 This was perl v5.40.0, dated 2025-01-10, and it's filed under EBook:...EReader(3pm). Go forth and parse some .pdb files, you've got this πŸ’–πŸŽ€βœ¨

πŸ“¦ where this page comes from