Data::...::Text(3pm)

πŸ“¦
version 0.35 Β· 2 versions
  • 0.35 Β· debian bookworm, debian trixie, ubuntu noble, ubuntu resolute, ubuntu stonking (latest)
  • 0.35 Β· ubuntu jammy
, in debian bookworm, debian trixie, ubuntu noble, ubuntu resolute, ubuntu stonking

πŸ’– Data::Phrasebook::Loader::Text β€” the manual, but make it cute πŸ’–

okay so bestie, welcome to Data::...::Text(3pm) β€” yes the header says Data::...::Text(3pm) but the actual module living inside is Data::Phrasebook::Loader::Text, and it is the loader plugin for keeping your phrases in plain text files. Perl, User Contributed Perl Documentation, all of it. Let's get into it ✨


🌸 NAME 🌸

Data::Phrasebook::Loader::Text β€” abstract your phrases with plain text files. that's it, that's the whole vibe πŸŽ€


πŸ¦‹ SYNOPSIS πŸ¦‹

use Data::Phrasebook;

my $q = Data::Phrasebook->new(
    class  => 'Fnerk',
    loader => 'Text',
    file   => 'phrases.txt',
);

# use default delimiters (:variable)
my $phrase = $q->fetch($keyword,{variable => 'substitute'});

# use Template Toolkit style delimiters
$q->delimiters( qr{ \[% \s* (\w+) \s* %\] }x );
my $phrase = $q->fetch($keyword,{variable => 'substitute'});

like, look at that. you got your default (:variable) delimiters, and then boom, you can flip to Template Toolkit style delimiters with delimiters(). iconic behaviour honestly πŸ’…


✨ DESCRIPTION ✨

This loader plugin implements phrasebook patterns using plain text files. no cap.

Phrases can be contained within one or more dictionaries, with each phrase accessible via a unique key. Phrases may contain placeholders β€” please see Data::Phrasebook for an explanation of how to use these, because that's where the full lore lives. Groups of phrases are kept in a dictionary. In this implementation a single file is one complete dictionary. one file = one dictionary, periodt.

An example plain text file:

foo=Welcome to :my world. It is a nice :place.

Within the phrase text placeholders can be used, which are then replaced with the appropriate values once the get() method is called. The default style of placeholders can be altered using the delimiters() method. so you can change the placeholder drip whenever you want 🫢


🌈 INHERITANCE 🌈

Data::Phrasebook::Loader::Text inherits from the base class Data::Phrasebook::Loader::Base. See that module for other available methods and documentation β€” it's the parent, it's giving main character energy, go read it πŸ’œ


πŸ‘‘ METHODS πŸ‘‘

πŸ“ load

Given a file, load it. file must contain a valid phrase map. no valid phrase map, no load, that's the deal.

my $file = 'english.txt';
$loader->load( $file );

This method is used internally by Data::Phrasebook::Generic's data method, to initialise the data store. lowkey the plumbing, but we love her.

To utilise the dictionary framework for a Plain Text phrasebook, the idea is to use a directory of files, where the directory is passed via the file argument and the dictionary β€” the specific name of the file β€” is passed via the dictionary argument.

my $file = '/tmp/phrasebooks';
my $dictionary = 'english.txt';
$loader->load( $file, $dictionary );

🧚 get

Returns the phrase stored in the phrasebook, for a given keyword. hand it a keyword, get a phrase back. slay.

my $value = $loader->get( $key );

πŸ’€ dicts

Having instantiated the Data::Phrasebook object class, and using the file attribute as a directory path, the object can return a list of the current dictionaries available as:

my $pb = Data::Phrasebook->new(
  loader => 'Text',
  file   => '/tmp/phrasebooks',
);

my @dicts = $pb->dicts;

or

my @dicts = $pb->dicts( $path );

πŸ’… keywords

Having instantiated the Data::Phrasebook object class, using the file and dict attributes as required, the object can return a list of the current keywords available as:

my $pb = Data::Phrasebook->new(
  loader => 'Text',
  file   => '/tmp/phrasebooks',
  dict   => 'TEST',
);

my @keywords = $pb->keywords;

or

my @keywords = $pb->keywords( $path, $dict );

Note that $path can either be the directory path, where $dict must be the specific file name of the dictionary, or the full path of the dictionary file.

In the second instance, the function will not load a dictionary, but can be used to interrogate the contents of a known dictionary. so it's a little peek at what's already there, not a fresh load. iykyk πŸ”₯


πŸ’œ SEE ALSO πŸ’œ

Data::Phrasebook.


πŸŽ€ SUPPORT πŸŽ€

Please see the README file. that's where the help lives, bestie πŸ™ˆ


🌟 AUTHOR 🌟

Barbie, <barbie@cpan.org>
for Miss Barbell Productions <http://www.missbarbell.co.uk>.

Copyright (C) 2004-2013 Barbie for Miss Barbell Productions.

This distribution is free software; you can redistribute it and/or
modify it under the Artistic License v2.

okay real talk: this whole thing is free software, you can redistribute and/or modify it under the Artistic License v2, and that's not a vibe, that's a fact. 🫢

and that's the page, babe β€” written by Barbie for Miss Barbell Productions, dated 2022-11-19, running on perl v5.36.0, and it's the Data::...::Text(3pm) manual. go forth and phrasebook πŸ’–βœ¨πŸŒΈ