Data::...Generic(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::...Generic πŸ’…

okay bestie, so this is Data::Phrasebook::Generic β€” it's the base class for Phrasebook Models, from the User Contributed Perl Documentation section (man page Data::...Generic(3pm) if you're keeping score). it's giving "foundation that everything else is built on" and honestly? iconic. πŸ‘‘


🌸 SYNOPSIS

use Data::Phrasebook;

my $q = Data::Phrasebook->new(
    class  => 'Fnerk',
    loader => 'XML',
    file   => 'phrases.xml',
    dict   => 'English',
);

like, that's the whole vibe. you make a phrasebook, you tell it where the phrases live, you go off. slay. ✨


πŸ¦‹ DESCRIPTION

so this module hands you a base class for phrasebook implementations. that's it, that's the job. it's the parent everybody inherits from. 🫢


πŸŽ€ CONSTRUCTOR

new

new takes an optional hash of arguments. here's the cute part: each value in the hash gets handed to a method with the same name as its key. so key file β†’ method file. no cap.

ngl bestie, you should never need to call this constructor directly, because Phrasebook creation is supposed to go through the Data::Phrasebook factory. let the factory cook. πŸ§‘πŸ³

subclasses should provide at least an accessor method to retrieve values for a named key. you can overload further methods, but they have to keep a standard API to the overloaded method β€” no rogue chaos, we're keeping it consistent.

and like, all of them. or at least most of them. all, or at least most, phrasebook implementations should inherit from this class. πŸ’œ


πŸ”₯ METHODS

loader

set, or get, the loader class. if you don't specify one it uses a default. go read Data::Phrasebook::Loader for the tea. ✨

unload

called by the file() and dict() methods whenever a fresh file or dictionary is specified and a reload is required. it's the lil reset button bestie. πŸ”„

loaded

accessor that tells you whether the current dictionary has been loaded. vibe check for your dict. βœ…

file

a description of a file that gets passed to the loader. in most cases, yes, it's literally a file. BUT β€” a loader that pulls its data from a database could conceivably have this be a hash, like so:

$q->file( {
    dsn => "dbi:SQLite:dbname=bookdb",
    table => 'phrases',
} );

so basically: which loader you use determines what your file looks like. the default loader takes just an ordinary filename. simple. clean. periodt. πŸ’…

dict

accessor to store the dictionary to be used. that's it. that's the whole method. πŸ“

dicts

so once you've instantiated the Data::Phrasebook object class and you're using the file attribute as a directory path, the object can return a list of the current dictionaries available β€” provided the plugin supports it β€” like this:

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

my @dicts = $pb->dicts;

or, alternatively:

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

look at all those dicts. so many options. we love range. 🌈

keywords

same energy, different attribute: instantiate the Data::Phrasebook object class, use the dict attribute as required, and the object can return a list of the current keywords available β€” provided the plugin supports it β€” like so:

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

my @keywords = $pb->keywords;

or:

my @keywords = $pb->keywords( $dict );
⚠️ heads up bestie: the list will be a combination of the default and any named dictionary. however, not all Loader plugins may support the second usage. so like, check before you commit, iykyk. πŸ™ˆ

data

loads the data source, if it's not already loaded, and returns the data block associated with the given key.

my $data = $self->data($key);

this is typically only used internally by implementations, not by the end user. so if you're the end user... this one's not for you babe. it's behind the scenes main character energy. 🎭

delimiters

returns or sets the current delimiters for substitution variables. it must be a regular expression with at least one capture group. no capture group, no service. 🚫

the example below shows the default ':variable' style regex:

$q->delimiters( qr{ :(\w+) }x );

and this one shows a Template Toolkit style regex:

$q->delimiters( qr{ \[% \s* (\w+) \s* %\] }x );

✨ and there's more ✨ β€” in addition to the delimiter pattern, you can pass an optional setting to suppress missing value errors after the pattern. if it's set to a true value, it'll turn any unmatched delimiter patterns into an empty string. quiet, peaceful, no drama. πŸ’–


🌟 SEE ALSO

  • Data::Phrasebook
  • Data::Phrasebook::Loader

go read them. they're the extended universe. πŸ“š


🫢 SUPPORT

please see the README file. that's where the help lives bestie. πŸ’Œ


πŸ‘‘ AUTHOR

Original author: Iain Campbell Truskett (16.07.1979 - 29.12.2003)
Maintainer: Barbie <barbie@cpan.org> since January 2004.
for Miss Barbell Productions <http://www.missbarbell.co.uk>.

shoutout to the original author, and to Barbie for carrying the maintainer torch since January 2004. legends only. πŸ•―οΈπŸ’œ


Copyright (C) 2003 Iain Truskett.
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.

free software, Artistic License v2, go wild (respectfully). ✨


aaaand that's the whole page bestie! this was perl v5.36.0, dated 2022-11-19 β€” the Data::...Generic(3pm) moment. go forth and inherit responsibly. πŸ’…πŸŽ€πŸ¦‹