| 1 | package Test::DBIC::Schema::Connector; | ||||||||||||||
| 2 | 5 | our $AUTHORITY = 'cpan:GETTY'; | |||||||||||||
| 3 | 5 | $Test::DBIC::Schema::Connector::VERSION = '0.003'; | |||||||||||||
| 4 | # ABSTRACT: Generate an instance of a DBIx::Class::Schema as test database | ||||||||||||||
| 5 | 5 | ▶ | use Exporter::Lite; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 6 | |||||||||||||||
| 7 | 5 | @EXPORT = qw( test_dbic_schema_connect ); | |||||||||||||
| 8 | |||||||||||||||
| 9 | 5 | ▶ | use strict; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 10 | 5 | ▶ | use warnings; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 11 | 5 | ▶ | use File::Temp qw/tempdir/; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 12 | |||||||||||||||
| 13 | 5 | ▶ | use Data::Dumper; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 14 | |||||||||||||||
| 15 | 4 | ▶ | sub test_dbic_schema_connect { | ||||||||||||
|
Subroutine
test_dbic_schema_connect: called CC=16 SCAR=27.7
Pod
documented
| |||||||||||||||
| 16 | 4 | my ( $schema_package, $options ) = @_; | |||||||||||||
| 17 | 4 | ▶ | $options = {} if !$options; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 18 | 4 | my $env_prefix; | |||||||||||||
| 19 | 4 | ▶ | $env_prefix = $options->{env_prefix} if defined $options->{env_prefix}; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 20 | 4 | ▶ | if (!$env_prefix) { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 21 | 3 | $env_prefix = uc($schema_package); | |||||||||||||
| 22 | 3 | $env_prefix =~ s/::/_/g; | |||||||||||||
| 23 | } | ||||||||||||||
| 24 | 4 | ▶ | my $env_user = defined $options->{env_user} ? $options->{env_user} : $env_prefix.'_USER'; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 25 | 4 | ▶ | my $env_pass = defined $options->{env_pass} ? $options->{env_pass} : $env_prefix.'_PASS'; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 26 | 4 | ▶ | my $env_dsn = defined $options->{env_dsn} ? $options->{env_dsn} : $env_prefix.'_DSN'; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 27 | 4 | ▶ | my $user = defined $options->{user} ? $options->{user} : defined $ENV{$env_user} ? $ENV{$env_user} : ''; | ||||||||||||
|
Branch: 2 branches
| |||||||||||||||
| 28 | 4 | ▶ | my $pass = defined $options->{pass} ? $options->{pass} : defined $ENV{$env_pass} ? $ENV{$env_pass} : ''; | ||||||||||||
|
Branch: 2 branches
| |||||||||||||||
| 29 | 4 | ▶ | my $dsn = defined $options->{dsn} ? $options->{dsn} : defined $ENV{$env_dsn} ? $ENV{$env_dsn} : undef; | ||||||||||||
|
Branch: 2 branches
| |||||||||||||||
| 30 | 4 | my $tmpdir; | |||||||||||||
| 31 | 4 | ▶ | if (!$dsn) { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 32 | 1 | $tmpdir = tempdir; | |||||||||||||
| 33 | 1 | $dsn = 'dbi:SQLite:dbname='.$tmpdir.'/database.sqlite'; | |||||||||||||
| 34 | } | ||||||||||||||
| 35 | |||||||||||||||
| 36 | 4 | my $schema = $schema_package->connect($dsn,$user,$pass); | |||||||||||||
| 37 | 4 | ▶ | $schema->{tmpdir_storage_for_test_dbic_schema_connector} = $tmpdir if $tmpdir; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 38 | 4 | ▶ | $schema->deploy if !$options->{no_deploy}; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 39 | |||||||||||||||
| 40 | 4 | my ( $file ) = $dsn =~ m/(\/tmp\/\w+\/.+)$/g; | |||||||||||||
| 41 | |||||||||||||||
| 42 | 4 | return $schema; | |||||||||||||
| 43 | } | ||||||||||||||
| 44 | |||||||||||||||
| 45 | 5 | 1; | |||||||||||||
| 46 | |||||||||||||||
| 47 | __END__ | ||||||||||||||