blib/lib/Test/DBIC/Schema/Connector.pm

filter: Statementstmt 100% 41 / 41 Branchbran 96.6% 29 / 30 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 6 / 6 Podpod 100% 1 / 1 totaltotal 98.7% 77 / 78 CC 16 SCAR 25.2
CC
16
Cov
99%
test_dbic_schema_connect
16.0
BEGIN
1.0
BEGIN
1.0
CRAP 12.4
↑ Summary
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
BranchTrueFalseTotal
unless $options 1 3 4
18 4 my $env_prefix;
19 4 ▶ $env_prefix = $options->{env_prefix} if defined $options->{env_prefix};
Branch: 1 branch
BranchTrueFalseTotal
if defined $options->{"env_prefix"} 1 3 4
20 4 ▶ if (!$env_prefix) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($env_prefix) 3 1 4
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
BranchTrueFalseTotal
defined $options->{'env_user'} ? : 1 3 4
25 4 ▶ my $env_pass = defined $options->{env_pass} ? $options->{env_pass} : $env_prefix.'_PASS';
Branch: 1 branch
BranchTrueFalseTotal
defined $options->{'env_pass'} ? : 1 3 4
26 4 ▶ my $env_dsn = defined $options->{env_dsn} ? $options->{env_dsn} : $env_prefix.'_DSN';
Branch: 1 branch
BranchTrueFalseTotal
defined $options->{'env_dsn'} ? : 1 3 4
27 4 ▶ my $user = defined $options->{user} ? $options->{user} : defined $ENV{$env_user} ? $ENV{$env_user} : '';
Branch: 2 branches
BranchTrueFalseTotal
defined $options->{'user'} ? : 1 3 4
defined $ENV{$env_user} ? : 2 1 3
28 4 ▶ my $pass = defined $options->{pass} ? $options->{pass} : defined $ENV{$env_pass} ? $ENV{$env_pass} : '';
Branch: 2 branches
BranchTrueFalseTotal
defined $options->{'pass'} ? : 1 3 4
defined $ENV{$env_pass} ? : 2 1 3
29 4 ▶ my $dsn = defined $options->{dsn} ? $options->{dsn} : defined $ENV{$env_dsn} ? $ENV{$env_dsn} : undef;
Branch: 2 branches
BranchTrueFalseTotal
defined $options->{'dsn'} ? : 1 3 4
defined $ENV{$env_dsn} ? : 2 1 3
30 4 my $tmpdir;
31 4 ▶ if (!$dsn) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($dsn) 1 3 4
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
BranchTrueFalseTotal
if $tmpdir 1 3 4
38 4 ▶ $schema->deploy if !$options->{no_deploy};
Branch: 1 branch
BranchTrueFalseTotal
unless $options->{"no_deploy"} 4 0 4
39
40 4 my ( $file ) = $dsn =~ m/(\/tmp\/\w+\/.+)$/g;
41
42 4 return $schema;
43 }
44  
45 5 1;
46  
47 __END__
↑ Summary