NAME

Data::Phrasebook::Loader::DBI - Absract your phrases with a DBI driver.

SYNOPSIS

use Data::Phrasebook;

my $q = Data::Phrasebook->new(
    class     => 'Fnerk',
    loader    => 'DBI',
    file      => {
        dsn       => 'dbi:mysql:database=test',
        dbuser    => 'user',
        dbpass    => 'pass',
        dbtable   => 'phrasebook',
        dbcolumns => ['keyword','phrase','dictionary'],
    }
);

OR

my $q = Data::Phrasebook->new(
    class     => 'Fnerk',
    loader    => 'DBI',
    file      => {
        dbh       => $dbh,
        dbtable   => 'phrasebook',
        dbcolumns => ['keyword','phrase','dictionary'],
    }
);

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

DESCRIPTION

This class loader implements phrasebook patterns using DBI.

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. Groups of phrases are kept in a dictionary. The first dictionary is used as the default, unless a specific dictionary is requested.

This module provides a base class for phrasebook implementations via a database. Note that the order of table columns is significant. If there is no dictionary field, all entries are assumed to be part of the default dictionary.

DICTIONARIES

In the instance where a dictionary column is specified, but no dictionary name is set, all dictionaries are searched, returned in lexical order native to the DB.

INHERITANCE

Data::Phrasebook::Loader::DBI inherits from the base class Data::Phrasebook::Loader::Base. See that module for other available methods and documentation.

METHODS

load

Given the appropriate settings, connects to the designated database. Note that for consistency, the connection string and other database specific settings, are passed via a hashref.

$loader->load( $file );

The hashref can be either:

my $file => {
         dsn       => 'dbi:mysql:database=test',
         dbuser    => 'user',
         dbpass    => 'pass',
         dbtable   => 'phrasebook',
         dbcolumns => ['keyword','phrase','dictionary'],
};

which will create a connection to the specified database. Or:

my $file => {
         dbh       => $dbh,
         dbtable   => 'phrasebook',
         dbcolumns => ['keyword','phrase','dictionary'],
};

which will reuse and already established connection.

This method is used internally by Data::Phrasebook::Generic's data method, to initialise the data store.

get

Returns the phrase stored in the phrasebook, for a given keyword.

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

dicts

Returns the list of dictionaries available.

my @dicts = $loader->dicts();

keywords

Returns the list of keywords available. List is lexically sorted.

my @keywords = $loader->keywords();

SEE ALSO

Data::Phrasebook.

BUGS, PATCHES & FIXES

There are no known bugs at the time of this release. However, if you spot a bug or are experiencing difficulties, that is not explained within the POD documentation, please send an email to barbie@cpan.org or submit a bug to the RT system (http://rt.cpan.org/). However, it would help greatly if you are able to pinpoint problems or even supply a patch.

Fixes are dependent upon their severity and my availability. Should a fix not be forthcoming, please feel free to (politely) remind me.

AUTHOR

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

COPYRIGHT AND LICENSE

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

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