Data::Phrasebook::Generic - Base class for Phrasebook Models
use Data::Phrasebook; my $q = Data::Phrasebook->new( class => 'Fnerk', loader => 'XML', file => 'phrases.xml', dict => 'English', );
This module provides a base class for phrasebook implementations.
new 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.
new
This constructor should never need to be called directly as Phrasebook creation should go through the Data::Phrasebook factory.
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 API to the overloaded method.
All, or at least most, phrasebook implementations should inherit from this class.
Set, or get, the loader class. Uses a default if none have been specified. See Data::Phrasebook::Loader.
Called by the file() and dict() methods when a fresh file or dictionary is specified, and reloading is required.
Accessor to determine whether the current dictionary has been loaded
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:
$q->file( { dsn => "dbi:SQLite:dbname=bookdb", table => 'phrases', } );
That is, which loader you use determines what your file looks like.
file
The default loader takes just an ordinary filename.
Accessor to store the dictionary to be used.
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 (provided the plugin supports it) as:
Data::Phrasebook
my $pb = Data::Phrasebook->new( loader => 'Text', file => '/tmp/phrasebooks', ); my @dicts = $pb->dicts;
or
my @dicts = $pb->dicts( $path );
Having instantiated the Data::Phrasebook object class, using the dict attribute as required, the object can return a list of the current keywords available (provided the plugin supports it) as:
dict
my $pb = Data::Phrasebook->new( loader => 'Text', file => '/tmp/phrasebooks', dict => 'TEST', ); my @keywords = $pb->keywords;
my @keywords = $pb->keywords( $dict );
Note the list will be a combination of the default and any named dictionary. However, not all Loader plugins may support the second usage.
Loads the data source, if 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 the end user.
Returns or sets the current delimiters for substitution variables. Must be a regular expression with at least one capture group.
The example below shows the default ':variable' style regex.
$q->delimiters( qr{ :(\w+) }x );
The example below shows a Template Toolkit style regex.
$q->delimiters( qr{ \[% \s* (\w+) \s* %\] }x );
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.
Data::Phrasebook, Data::Phrasebook::Loader.
Please see the README file.
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>.
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.
To install Data::Phrasebook, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Data::Phrasebook
CPAN shell
perl -MCPAN -e shell install Data::Phrasebook
For more information on module installation, please visit the detailed CPAN module installation guide.