.\" 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 3pm" .TH Data::Phrasebook 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 \- Abstract your queries! .SH "SYNOPSIS" .IX Header "SYNOPSIS" .Vb 1 \& use Data::Phrasebook; \& \& my $q = Data::Phrasebook\->new( \& class => \*(AqPlain\*(Aq, \& loader => \*(AqText\*(Aq, \& file => \*(Aqphrases.txt\*(Aq, \& ); \& \& # simple keyword to phrase mapping \& my $phrase = $q\->fetch($keyword); \& \& # keyword to phrase mapping with parameters \& $q\->delimiters( qr{ \e[% \es* (\ew+) \es* %\e] }x ); \& my $phrase = $q\->fetch($keyword,{this => \*(Aqthat\*(Aq}); .Ve .SH "DESCRIPTION" .IX Header "DESCRIPTION" Data::Phrasebook is a collection of modules for accessing phrasebooks from various data sources. .SH "PHRASEBOOKS" .IX Header "PHRASEBOOKS" To explain what phrasebooks are it is worth reading Rani Pinchuk's (author of Class::Phrasebook) article on Perl.com: .PP .PP Common uses of phrasebooks are in handling error codes, accessing databases via \s-1SQL\s0 queries and written language phrases. Examples are the mime.types file and the hosts file, both of which use a simple phrasebook design. .PP Unfortunately Class::Phrasebook is a complete work and not a true class based framework. If you can't install \s-1XML\s0 libraries, you cannot use it. This distribution is a collaboration between Iain Truskett and myself to create an extendable and class based framework for implementing phrasebooks. .SH "CLASSES" .IX Header "CLASSES" In creating a phrasebook object, a class type is required. This class defines the nature of the phrasebook or the behaviours associated with it. Currently there are two classes, Plain and \s-1SQL.\s0 .PP The Plain class is the default class, and allows retrieval of phrases via the \&\fBfetch()\fR method. The \fBfetch()\fR simply returns the phrase that maps to the given keyword. .PP The \s-1SQL\s0 class allows specific database handling. Phrases are retrieved via the \&\fBquery()\fR method. The \fBquery()\fR method internally retrieves the \s-1SQL\s0 phrase, then returns the statement handler object, which the user can then perform a prepare/execute/fetch/finish sequence on. For more details see Data::Phrasebook::SQL. .SH "CONSTRUCTOR" .IX Header "CONSTRUCTOR" .SS "new" .IX Subsection "new" The arguments to new depend upon the exact class you're creating. .PP The default class is \f(CW\*(C`Plain\*(C'\fR and only requires the Loader arguments. The \&\f(CW\*(C`SQL\*(C'\fR class requires a database handle as well as the Loader arguments. .PP The \f(CW\*(C`class\*(C'\fR argument defines the object class of the phrasebook and the behaviours that can be associated with it. Using \f(CW\*(C`Foobar\*(C'\fR as a fake class, the class module is searched for in the following order: .IP "1." 4 If you've subclassed \f(CW\*(C`Data::Phrasebook\*(C'\fR, for example as \f(CW\*(C`Dictionary\*(C'\fR, then \f(CW\*(C`Dictionary::Foobar\*(C'\fR is tried. .IP "2." 4 If that failed, \f(CW\*(C`Data::Phrasebook::Foobar\*(C'\fR is tried. .IP "3." 4 If \fBthat\fR failed, \f(CW\*(C`Foobar\*(C'\fR is tried. .IP "4." 4 If all the above failed, we croak. .PP This should allow you some flexibility in what sort of classes you use while not having you type too much. .PP For other parameters, see the specific class you wish to instantiate. The class argument is removed from the arguments list and the \f(CW\*(C`new\*(C'\fR method of the specified class is called with the remaining arguments. .SH "DELIMITERS" .IX Header "DELIMITERS" Delimiters allow for variable substitution in the phrase. The default style is ':variable', which would be passed as: .PP .Vb 1 \& $q\->delimiters( qr{ :(\ew+) }x ); .Ve .PP As an alternative, a Template Toolkit style would be passed as: .PP .Vb 1 \& $q\->delimiters( qr{ \e[% \es* (\ew+) \es* %\e] }x ); .Ve .SH "DICTIONARIES" .IX Header "DICTIONARIES" .SS "Simple Dictionaries" .IX Subsection "Simple Dictionaries" Data::Phrasebook supports the use of dictionaries. See the specific Loader module to see how to implement the dictionary within your phrasebook. Using Data::Phrasebook::Loader::Ini as an example, the dictionary might be laid out as: .PP .Vb 3 \& [Stuff] \& language=Perl \& platform=Linux \& \& [Nonsense] \& platform=Windows .Ve .PP The phrasebook object is then created and used as: .PP .Vb 6 \& my $q = Data::Phrasebook\->new( \& class => \*(AqPlain\*(Aq, \& loader => \*(AqIni\*(Aq, \& file => \*(Aqphrases.ini\*(Aq, \& dict => \*(AqNonsense\*(Aq, \& ); \& \& my $language = $q\->fetch(\*(Aqlanguage\*(Aq); # retrieves \*(AqPerl\*(Aq \& my $platform = $q\->fetch(\*(Aqplatform\*(Aq); # retrieves \*(AqWindows\*(Aq .Ve .PP The former is from the default (first) dictionary, and the second is from the named dictionary ('Nonsense'). If a phrase is not found in the named dictionary an attempt is made to find it in the default dictionary. Otherwise undef will be returned. .PP Once a dictionary or file is specified, changing either requires reloading. As this is done at the loader stage, we need to let it know what it needs to reload. This can be done with the either (or both) of the following: .PP .Vb 2 \& $q\->file(\*(Aqphrases2.ini\*(Aq); \& $q\->dict(\*(AqStuff\*(Aq); .Ve .PP A subsequent \fBfetch()\fR will then reload the file and dictionary, before retrieving the phrase required. However, a reload only takes place if both the file and the dictionary passed are not the ones currently loaded. .SS "Multiple Dictionaries" .IX Subsection "Multiple Dictionaries" As of version 0.25, the ability to provide prescendence over multiple dictionaries for the same phrasebook. Using Data::Phrasebook::Loader::Ini again as an example, the phrasebook might be laid out as: .PP .Vb 4 \& [AndTheOther] \& language=Perl \& platform=Linux \& network=LAN \& \& [That] \& platform=Solaris \& network=WLAN \& \& [This] \& platform=Windows .Ve .PP The phrasebook object is then created and used as: .PP .Vb 6 \& my $q = Data::Phrasebook\->new( \& class => \*(AqPlain\*(Aq, \& loader => \*(AqIni\*(Aq, \& file => \*(Aqphrases.ini\*(Aq, \& dict => [\*(AqThis\*(Aq,\*(AqThat\*(Aq,\*(AqAndTheOther\*(Aq], \& ); \& \& my $language = $q\->fetch(\*(Aqlanguage\*(Aq); # retrieves \*(AqPerl\*(Aq \& my $platform = $q\->fetch(\*(Aqplatform\*(Aq); # retrieves \*(AqWindows\*(Aq \& my $network = $q\->fetch(\*(Aqnework\*(Aq); # retrieves \*(AqWLAN\*(Aq .Ve .PP The first dictionary, if not specified and supported by the Loader module, is still used as the default dictionary. .PP The dictionaries can be specified, or reordered, using the object method: .PP .Vb 1 \& $q\->dict(\*(AqThat\*(Aq,\*(AqAndTheOther\*(Aq,\*(AqThis\*(Aq); .Ve .PP A subsequent reload will occur with the next fetch call. .SH "DEDICATION" .IX Header "DEDICATION" Much of the code for the original class framework is from Iain's original code. My code was much simpler and was tied to using just an \s-1INI\s0 data source. Merging all the ideas and code together we came up with this distribution. .PP Unfortunately Iain died in December 2003, so he never got to see or play with the final working version. I can only thank him for his thoughts and ideas in getting this distribution into a state worthy of release. .PP .Vb 1 \& Iain Campbell Truskett (16.07.1979 \- 29.12.2003) .Ve .SH "SEE ALSO" .IX Header "SEE ALSO" Data::Phrasebook::Plain, Data::Phrasebook::SQL, Data::Phrasebook::SQL::Query, Data::Phrasebook::Debug, Data::Phrasebook::Generic, Data::Phrasebook::Loader, Data::Phrasebook::Loader::Text, Data::Phrasebook::Loader::Base. .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