Chado.pm

filter: Statementstmt 61.3% 62 / 101 Branchbran 9.3% 3 / 32 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 77.7% 21 / 27 Podpod n/a totaltotal 53.7% 86 / 160 CC 17 SCAR 21.5
CC
17
Cov
49%
_prepare_fixture_loader_instance
31.4
__ANON__
14.4
__ANON__
6.0
CRAP 8.6
« Chado/DBManager/Pg.pm ↑ Summary Chado/Role/Helper/WithBcs.pm »
1 package Test::Chado;
2 {
3 14 $Test::Chado::VERSION = 'v4.1.1';
4 }
5 14 ▶use feature qw/say/;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 14 ▶use Test::Chado::Factory::DBManager;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 14 ▶use Test::Chado::Factory::FixtureLoader;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 14 ▶use Test::Chado::Types qw/MaybeFixtureLoader MaybeDbManager/;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 14 ▶use Types::Standard qw/Str Bool/;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 14 ▶use Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 14 ▶use DBI;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 14 ▶use MooX::ClassAttribute;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 14 ▶use Sub::Exporter -setup => {
Subroutine BEGIN: called CC=1 SCAR=0.0
14 exports => [
15 'chado_schema' => \&_build_schema,
16 'drop_schema' => \&_drop_schema,
17 'reload_schema' => \&_reload_schema,
18 'set_fixture_loader_type' => \&_set_fixture_loader_type,
19 'get_fixture_loader_instance' => \&_get_fixture_loader_instance,
20 'set_fixture_loader_instance' => \&_set_dbmanager_instance,
21 'set_dbmanager_instance' => \&_set_dbmanager_instance,
22 'get_dbmanager_instance' => \&_get_dbmanager_instance,
23 ],
24 groups => {
25 'schema' => [qw/chado_schema reload_schema drop_schema/],
26 'manager' => [
27 qw/get_fixture_loader_instance set_fixture_loader_instance
28 get_dbmanager_instance set_dbmanager_instance/
29 ]
30 }
31 14 };
32  
33 14 class_has 'ignore_tc_env' => (
34 is => 'rw', isa => Bool, default => 0 , lazy => 1
35 );
36  
37 14 class_has 'is_schema_loaded' =>
38 ( is => 'rw', isa => Bool, default => 0, lazy => 1 );
39  
40 14 class_has '_fixture_loader_instance' => (
41 is => 'rw',
42 isa => MaybeFixtureLoader,
43 clearer => 1
44 );
45  
46 14 class_has '_dbmanager_instance' => (
47 is => 'rw',
48 isa => MaybeDbManager,
49 clearer => 1
50 );
51  
52 14 class_has '_fixture_loader_type' =>
53 ( is => 'rw', isa => Str, default => 'preset', lazy => 1 );
54  
55 1 ▶sub _set_fixture_loader_type {
Subroutine _set_fixture_loader_type: called CC=1 SCAR=3.1
56 1 my ($class) = @_;
57 0 ▶ return sub {
Subroutine __ANON__: not called CC=2 SCAR=17.9
58 0 my ($arg) = @_;
59 0 ▶ if ($arg) {
Branch: 1 branch
BranchTrueFalseTotal
if ($arg) 0 0 0
60 0 $class->_fixture_loader_type($arg);
61 }
62 1 };
63 }
64  
65 0 ▶sub _set_fixture_loader_instance {
Subroutine _set_fixture_loader_instance: not called CC=1 SCAR=6.9
66 0 my ($class) = @_;
67 0 ▶ return sub {
Subroutine __ANON__: not called CC=2 SCAR=17.9
68 0 my ($arg) = @_;
69 0 ▶ if ($arg) {
Branch: 1 branch
BranchTrueFalseTotal
if ($arg) 0 0 0
70 0 $class->_fixture_loader_instance($arg);
71 }
72 0 };
73 }
74  
75 1 ▶sub _get_fixture_loader_instance {
Subroutine _get_fixture_loader_instance: called CC=1 SCAR=0.2
76 1 my ($class) = @_;
77 2 ▶ return sub {
Subroutine __ANON__: called CC=2 SCAR=8.1
78 2 my $fixture_loader = $class->_fixture_loader_instance;
79 2 ▶ die "fixture loader is not initiated !!!\n" if !$fixture_loader;
Branch: 1 branch
BranchTrueFalseTotal
unless $fixture_loader 2 0 2
80 0 return $fixture_loader;
81 1 };
82 }
83  
84 2 ▶sub _set_dbmanager_instance {
Subroutine _set_dbmanager_instance: called CC=1 SCAR=3.1
85 2 my ($class) = @_;
86 0 ▶ return sub {
Subroutine __ANON__: not called CC=2 SCAR=17.9
87 0 my ($arg) = @_;
88 0 ▶ if ($arg) {
Branch: 1 branch
BranchTrueFalseTotal
if ($arg) 0 0 0
89 0 $class->_dbmanager_instance($arg);
90 }
91 2 };
92 }
93  
94 1 ▶sub _get_dbmanager_instance {
Subroutine _get_dbmanager_instance: called CC=1 SCAR=0.2
95 1 my ($class) = @_;
96 2 ▶ return sub {
Subroutine __ANON__: called CC=2 SCAR=8.1
97 2 my $dbmanager = $class->_dbmanager_instance;
98 2 ▶ die "dbmanager is not initiated !!!\n" if !$dbmanager;
Branch: 1 branch
BranchTrueFalseTotal
unless $dbmanager 2 0 2
99 0 return $dbmanager;
100 1 };
101 }
102  
103 3 ▶sub _reload_schema {
Subroutine _reload_schema: called CC=1 SCAR=3.1
104 3 my ($class) = @_;
105 0 ▶ return sub {
Subroutine __ANON__: not called CC=2 SCAR=17.9
106 0 ▶ my $fixture_loader
Branch: 1 branch
BranchTrueFalseTotal
$class->_fixture_loader_instance ? : 0 0 0
107 = $class->_fixture_loader_instance
108 ? $class->_fixture_loader_instance
109 : $class->_prepare_fixture_loader_instance;
110 0 $fixture_loader->dbmanager->reset_schema;
111 0 $class->is_schema_loaded(1);
112 3 };
113 }
114  
115 3 ▶sub _drop_schema {
Subroutine _drop_schema: called CC=1 SCAR=3.5
116 3 my ($class) = @_;
117 0 ▶ return sub {
Subroutine __ANON__: not called CC=2 SCAR=17.9
118 0 ▶ my $fixture_loader
Branch: 1 branch
BranchTrueFalseTotal
$class->_fixture_loader_instance ? : 0 0 0
119 = $class->_fixture_loader_instance
120 ? $class->_fixture_loader_instance
121 : $class->_prepare_fixture_loader_instance;
122 0 $fixture_loader->dbmanager->drop_schema;
123 0 $class->is_schema_loaded(0);
124 0 $class->_clear_fixture_loader_instance;
125 3 };
126 }
127  
128 3 ▶sub _build_schema {
Subroutine _build_schema: called CC=1 SCAR=3.7
129 3 my ($class) = @_;
130 2 ▶ return sub {
Subroutine __ANON__: called CC=4 SCAR=26.7
131 2 my (%arg) = @_;
132 2 my $fixture_loader
133 #= $class->_fixture_loader_instance
134 #? $class->_fixture_loader_instance
135 = $class->_prepare_fixture_loader_instance;
136  
137 #if ( !$class->is_schema_loaded ) {
138 0 $fixture_loader->dbmanager->deploy_schema;
139 #$class->is_schema_loaded(1);
140 #}
141 0 ▶ if ( defined $arg{'custom_fixture'} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $arg{"custom_fixture"}) 0 0 0
142 0 ▶ die
Branch: 1 branch
BranchTrueFalseTotal
if $class->_fixture_loader_type ne "preset" 0 0 0
143 "only **preset** fixture loader can be used with custom_fixture\n"
144 if $class->_fixture_loader_type ne 'preset';
145 0 $fixture_loader->load_custom_fixtures( $arg{'custom_fixture'} );
146 0 return $fixture_loader->dynamic_schema;
147 }
148  
149 $fixture_loader->load_fixtures
150 0 ▶ if defined $arg{'load_fixture'};
Branch: 1 branch
BranchTrueFalseTotal
if defined $arg{"load_fixture"} 0 0 0
151 0 return $fixture_loader->dynamic_schema;
152 3 };
153 }
154  
155 3 ▶sub _prepare_fixture_loader_instance {
Subroutine _prepare_fixture_loader_instance: called CC=7 SCAR=34.5
156 3 my ($class) = @_;
157 3 my ( $loader, $dbmanager );
158 3 ▶ if ($class->ignore_tc_env) {
Branch: 4 branches
BranchTrueFalseTotal
if ($class->ignore_tc_env) { } 3 0 3
elsif (exists $ENV{'TC_POSTGRESSION'}) { } 0 0 0
elsif (exists $ENV{'TC_TESTPG'}) { } 0 0 0
elsif (defined $ENV{'TC_DSN'}) { } 0 0 0
159 3 $dbmanager
160 = $class->_prepare_default_dbmanager;
161 }
162 elsif ( exists $ENV{TC_POSTGRESSION} ) {
163 0 $dbmanager
164 = Test::Chado::Factory::DBManager->get_instance('postgression');
165 }
166 elsif ( exists $ENV{TC_TESTPG} ) {
167 0 $dbmanager = Test::Chado::Factory::DBManager->get_instance('testpg');
168 }
169 elsif ( defined $ENV{TC_DSN} ) {
170 my ( $scheme, $driver, $attr_str, $attr_hash, $driver_dsn )
171 0 = DBI->parse_dsn( $ENV{TC_DSN} );
172 0 $dbmanager = Test::Chado::Factory::DBManager->get_instance($driver);
173 0 $dbmanager->dsn( $ENV{TC_DSN} );
174 0 ▶ $dbmanager->user( $ENV{TC_USER} ) if defined $ENV{TC_USER};
Branch: 1 branch
BranchTrueFalseTotal
if defined $ENV{"TC_USER"} 0 0 0
175 0 ▶ $dbmanager->password( $ENV{TC_PASS} ) if defined $ENV{TC_PASS};
Branch: 1 branch
BranchTrueFalseTotal
if defined $ENV{"TC_PASS"} 0 0 0
176 }
177 else {
178 0 $dbmanager
179 = $class->_prepare_default_dbmanager;
180 }
181  
182 3 $loader = Test::Chado::Factory::FixtureLoader->get_instance(
183 $class->_fixture_loader_type );
184 0 $loader->dbmanager($dbmanager);
185 0 $class->_dbmanager_instance($dbmanager);
186 0 $class->_fixture_loader_instance($loader);
187 0 return $loader;
188 }
189  
190 3 ▶sub _prepare_default_dbmanager {
Subroutine _prepare_default_dbmanager: called CC=1 SCAR=0.0
191 3 my ($class) = @_;
192 return
193 #$class->_dbmanager_instance
194 #? $class->_dbmanager_instance
195 3 Test::Chado::Factory::DBManager->get_instance('sqlite');
196  
197 }
198  
199 14 1;
200  
201 # ABSTRACT: Unit testing for chado database modules and applications
202  
203 __END__
« Chado/DBManager/Pg.pm ↑ Summary Chado/Role/Helper/WithBcs.pm »