.\" Automatically generated by Pod::Man 4.14 (Pod::Simple 3.43) .\" .\" Standard preamble: .\" ======================================================================== .de Sp \" Vertical space (when we can't use .PP) .if t .sp .5v .if n .sp .. .de Vb \" Begin verbatim text .ft CW .nf .ne \\$1 .. .de Ve \" End verbatim text .ft R .fi .. .\" Set up some character translations and predefined strings. \*(-- will .\" give an unbreakable dash, \*(PI will give pi, \*(L" will give a left .\" double quote, and \*(R" will give a right double quote. \*(C+ will .\" give a nicer C++. Capital omega is used to do unbreakable dashes and .\" therefore won't be available. \*(C` and \*(C' expand to `' in nroff, .\" nothing in troff, for use with C<>. .tr \(*W- .ds C+ C\v'-.1v'\h'-1p'\s-2+\h'-1p'+\s0\v'.1v'\h'-1p' .ie n \{\ . ds -- \(*W- . ds PI pi . if (\n(.H=4u)&(1m=24u) .ds -- \(*W\h'-12u'\(*W\h'-12u'-\" diablo 10 pitch . if (\n(.H=4u)&(1m=20u) .ds -- \(*W\h'-12u'\(*W\h'-8u'-\" diablo 12 pitch . ds L" "" . ds R" "" . ds C` "" . ds C' "" 'br\} .el\{\ . ds -- \|\(em\| . ds PI \(*p . ds L" `` . ds R" '' . ds C` . ds C' 'br\} .\" .\" Escape single quotes in literal strings from groff's Unicode transform. .ie \n(.g .ds Aq \(aq .el .ds Aq ' .\" .\" If the F register is >0, we'll generate index entries on stderr for .\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index .\" entries marked with X<> in POD. Of course, you'll have to process the .\" output yourself in some meaningful fashion. .\" .\" Avoid warning from groff about undefined register 'F'. .de IX .. .nr rF 0 .if \n(.g .if rF .nr rF 1 .if (\n(rF:(\n(.g==0)) \{\ . if \nF \{\ . de IX . tm Index:\\$1\t\\n%\t"\\$2" .. . if !\nF==2 \{\ . nr % 0 . nr F 2 . \} . \} .\} .rr rF .\" ======================================================================== .\" .IX Title "Data::Phrasebook::Generic 3pm" .TH Data::Phrasebook::Generic 3pm "2022-11-19" "perl v5.36.0" "User Contributed Perl Documentation" .\" For nroff, turn off justification. Always turn off hyphenation; it makes .\" way too many mistakes in technical documents. .if n .ad l .nh .SH "NAME" Data::Phrasebook::Generic \- Base class for Phrasebook Models .SH "SYNOPSIS" .IX Header "SYNOPSIS" .Vb 1 \& use Data::Phrasebook; \& \& my $q = Data::Phrasebook\->new( \& class => \*(AqFnerk\*(Aq, \& loader => \*(AqXML\*(Aq, \& file => \*(Aqphrases.xml\*(Aq, \& dict => \*(AqEnglish\*(Aq, \& ); .Ve .SH "DESCRIPTION" .IX Header "DESCRIPTION" This module provides a base class for phrasebook implementations. .SH "CONSTRUCTOR" .IX Header "CONSTRUCTOR" .SS "new" .IX Subsection "new" \&\f(CW\*(C`new\*(C'\fR takes an optional hash of arguments. Each value in the hash is given as an argument to a method of the same name as the key. .PP This constructor should \fBnever\fR need to be called directly as Phrasebook creation should go through the Data::Phrasebook factory. .PP Subclasses should provide at least an accessor method to retrieve values for a named key. Further methods can be overloaded, but must retain a standard \&\s-1API\s0 to the overloaded method. .PP All, or at least \fImost\fR, phrasebook implementations should inherit from \&\fBthis\fR class. .SH "METHODS" .IX Header "METHODS" .SS "loader" .IX Subsection "loader" Set, or get, the loader class. Uses a default if none have been specified. See Data::Phrasebook::Loader. .SS "unload" .IX Subsection "unload" Called by the \fBfile()\fR and \fBdict()\fR methods when a fresh file or dictionary is specified, and reloading is required. .SS "loaded" .IX Subsection "loaded" Accessor to determine whether the current dictionary has been loaded .SS "file" .IX Subsection "file" A description of a file that is passed to the loader. In most cases, this is a file. A loader that gets its data from a database could conceivably have this as a hash like thus: .PP .Vb 4 \& $q\->file( { \& dsn => "dbi:SQLite:dbname=bookdb", \& table => \*(Aqphrases\*(Aq, \& } ); .Ve .PP That is, which loader you use determines what your \f(CW\*(C`file\*(C'\fR looks like. .PP The default loader takes just an ordinary filename. .SS "dict" .IX Subsection "dict" Accessor to store the dictionary to be used. .SS "dicts" .IX Subsection "dicts" Having instantiated the \f(CW\*(C`Data::Phrasebook\*(C'\fR object class, and using the \f(CW\*(C`file\*(C'\fR attribute as a directory path, the object can return a list of the current dictionaries available (provided the plugin supports it) as: .PP .Vb 4 \& my $pb = Data::Phrasebook\->new( \& loader => \*(AqText\*(Aq, \& file => \*(Aq/tmp/phrasebooks\*(Aq, \& ); \& \& my @dicts = $pb\->dicts; .Ve .PP or .PP .Vb 1 \& my @dicts = $pb\->dicts( $path ); .Ve .SS "keywords" .IX Subsection "keywords" Having instantiated the \f(CW\*(C`Data::Phrasebook\*(C'\fR object class, using the \f(CW\*(C`dict\*(C'\fR attribute as required, the object can return a list of the current keywords available (provided the plugin supports it) as: .PP .Vb 5 \& my $pb = Data::Phrasebook\->new( \& loader => \*(AqText\*(Aq, \& file => \*(Aq/tmp/phrasebooks\*(Aq, \& dict => \*(AqTEST\*(Aq, \& ); \& \& my @keywords = $pb\->keywords; .Ve .PP or .PP .Vb 1 \& my @keywords = $pb\->keywords( $dict ); .Ve .PP Note the list will be a combination of the default and any named dictionary. However, not all Loader plugins may support the second usage. .SS "data" .IX Subsection "data" Loads the data source, if not already loaded, and returns the data block associated with the given key. .PP .Vb 1 \& my $data = $self\->data($key); .Ve .PP This is typically only used internally by implementations, not the end user. .SS "delimiters" .IX Subsection "delimiters" Returns or sets the current delimiters for substitution variables. Must be a regular expression with at least one capture group. .PP The example below shows the default ':variable' style regex. .PP .Vb 1 \& $q\->delimiters( qr{ :(\ew+) }x ); .Ve .PP The example below shows a Template Toolkit style regex. .PP .Vb 1 \& $q\->delimiters( qr{ \e[% \es* (\ew+) \es* %\e] }x ); .Ve .PP In addition to the delimiter pattern, an optional setting to suppress missing value errors can be passed after the pattern. If set to a true value, will turn any unmatched delimiter patterns to an empty string. .SH "SEE ALSO" .IX Header "SEE ALSO" Data::Phrasebook, Data::Phrasebook::Loader. .SH "SUPPORT" .IX Header "SUPPORT" Please see the \s-1README\s0 file. .SH "AUTHOR" .IX Header "AUTHOR" .Vb 3 \& Original author: Iain Campbell Truskett (16.07.1979 \- 29.12.2003) \& Maintainer: Barbie since January 2004. \& for Miss Barbell Productions . .Ve .SH "COPYRIGHT AND LICENSE" .IX Header "COPYRIGHT AND LICENSE" .Vb 2 \& 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. .Ve