NAME
Test::Database::Driver - Base class for Test::Database drivers
SYNOPSIS
package Test::Database::Driver::MyDatabase;
use strict;
use warnings;
use Test::Database::Driver;
our @ISA = qw( Test::Database::Driver );
sub _version {
my ($class) = @_;
...;
return $version;
}
sub create_database {
my ( $self, $dbname, $keep ) = @_;
...;
return $handle;
}
sub drop_database {
my ( $self, $name ) = @_;
...;
}
sub databases {
my ($self) = @_;
...;
return @databases;
}
DESCRIPTION
Test::Database::Driver
is a base class for creating Test::Database
drivers.
METHODS
The class provides the following methods:
- new( %args )
-
Create a new
Test::Database::Driver
object.If called as
Test::Database::Driver->new()
, requires adriver
parameter to define the actual object class. - name()
-
The driver's short name (everything after
Test::Database::Driver::
). - base_dir()
-
The directory where the driver should store all the files for its databases, if needed. Typically used by file-based database drivers.
- version()
-
version
object representing the version of the underlying database enginge. This object is build with the return value of_version()
. - drh()
-
The DBI driver for this driver.
- bare_dsn()
-
Return a bare Data Source Name, sufficient to connect to the database engine without specifying an actual database.
- username()
-
Return the connection username.
- password()
-
Return the connection password.
- connection_info()
-
Return the connection information triplet (
bare_dsn
,username
,password
). - as_string()
-
Return a string representation of the
Test::Database::Driver
, suitable to be saved in a configuration file. - handles( @requests )
-
Return
Test::Database::Handler
objects matching the given requests.If no request is given, return a handler for each of the existing databases.
- cleanup()
-
Remove the directory used by
Test::Database
drivers.
The class also provides a few helpful commands that may be useful for driver authors:
- available_dbname()
-
Return an unused database name that can be used to create a new database for the driver.
- dsn( $dbname )
-
Return a bare Data Source Name, for the database with the given
$dbname
. - register_drop( $dbname )
-
Register the database with the given
$dbname
to be dropped automatically when the current program ends.
WRITING A DRIVER FOR YOUR DATABASE OF CHOICE
The SYNOPSIS contains a good template for writing a Test::Database::Driver
class.
Creating a driver requires writing the following methods:
- _version()
-
Return the version of the underlying database engine.
- create_database( $name )
-
Create the database for the corresponding DBD driver.
Return a
Test::Database::Handle
in case of success, and nothing in case of failure to create the database. - drop_database( $name )
-
Drop the database named
$name
.
Some methods have defaults implementations in Test::Database::Driver
, but those can be overridden in the derived class:
- is_filebased()
-
Return a boolean value indicating if the database engine is file-based or not, i.e. if all the database information is stored in a file or a directory, and no external database server is needed.
- essentials()
-
Return the essential fields needed to serialize the driver.
- databases()
-
Return the names of all existing databases for this driver as a list (the default implementation is only valid for file-based drivers).
- cleanup()
-
Clean all databases created with names generated with
available_dbname()
.For file-based databases, the directory used by the
Test::Database::Driver
subclass will be deleted.
AUTHOR
Philippe Bruhat (BooK), <book@cpan.org>
COPYRIGHT
Copyright 2008-2009 Philippe Bruhat (BooK), all rights reserved.
LICENSE
This module is free software; you can redistribute it and/or modify it under the same terms as Perl itself.