Devel-Maypole
view release on metacpan or search on metacpan
lib/Devel/Maypole.pm view on Meta::CPAN
=head1 EXPORTS
Nothing is exported by default. You can import individual functions, or groups of functions
using these tags:
tag functions
-----------------------------------------------------------
:test database application run_standard_tests
:install install install_templates install_yaml_config install_ddl install_data
:find find find_templates find_yaml_config find_ddl find_data
=head1 TESTING UTILITIES
=over 4
=item database
Builds and populates an SQLite database in a temporary file, and returns a DBI connection
string to the database.
Suitable SQL files will be (ASAP) included in the distribution to build a reasonably complex
version of the beer database.
Returns a DBI connection string.
Options:
=over 4
=item ddl
Path to the SQL DDL (schema) file to use. A couple of suitable files are installed by this
distribution - C<beerdb.default.sql> and C<beerdb.simple.sql>.
=item data
Path to the SQL data file to use. A couple of suitable files are installed by this
distribution - C<beerdb.default.sql> and C<beerdb.simple.sql>.
=item unlink
Set false to not unlink the generated database file. Default true (unlink when script exits).
=back
=cut
sub database
{
my %args = @_;
my $ddl = $args{ddl} || die 'need a DDL file';
my $data = $args{data} || die 'need a data file';
my $unlink = defined $args{unlink} ? $args{unlink} : 1;
$DB_FILE = File::Temp->new( TEMPLATE => 'MaypoleTestDB_XXXXX',
SUFFIX => '.db',
UNLINK => $unlink,
);
$DB_FILE->close; # or SQLite thinks it's locked
my $driver = 'SQLite';
eval { require DBD::SQLite } or do {
warn "Error loading DBD::SQLite, trying DBD::SQLite2\n";
eval {require DBD::SQLite2} ? $driver = 'SQLite2'
: die "DBD::SQLite2 is not installed";
};
my $connect = "dbi:$driver:dbname=$DB_FILE";
my $dbh = DBI->connect( $connect );
my $ddl_sql = read_file( $ddl );
my $data_sql = read_file( $data );
my $sql = $ddl_sql.';'.$data_sql;
foreach my $statement ( split /;/, $sql )
{
$statement =~ s/\#.*$//mg; # strip # comments
$statement =~ s/auto_increment//g;
next unless $statement =~ /\S/;
eval { $dbh->do($statement) };
die "$@: $statement" if $@;
}
return $connect;
}
=item application
Builds a simple Maypole driver in a temporary file in the current directory.
Returns the package name of the application, which will be C<MaypoleTestApp_XXXXX>
where C<XXXXX> are random characters.
Options:
=over 4
=item plugins
Arrayref of plugin names, just as you would supply to C<use Maypole::Application>.
See C<Custom driver code> below.
=item config
Hashref of Maypole options, or a Maypole::Config object. See C<Configuration> below.
=item unlink
Set false to not unlink the generated application file. Default true (unlink when script exits).
=back
=cut
( run in 0.748 second using v1.01-cache-2.11-cpan-39bf76dae61 )