Chado/Role/HasDBManager.pm

filter: Statementstmt 93.0% 67 / 72 Branchbran 75.0% 3 / 4 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 93.7% 15 / 16 Podpod 100% 3 / 3 totaltotal 92.6% 88 / 95 CC 4 SCAR 4.0
CC
4
Cov
92%
deploy_by_dbi
3.0
deploy_schema
2.1
__ANON__
2.0
CRAP 1.5
« Chado/Factory/DBManager.pm ↑ Summary Chado/DBManager/Postgression.pm »
1 package Test::Chado::Role::HasDBManager;
2 {
3 12 $Test::Chado::Role::HasDBManager::VERSION = 'v4.1.1';
4 }
5  
6 12 ▶use namespace::autoclean;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 12 ▶use Moo::Role;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 12 ▶use MooX::late;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 12 ▶use File::ShareDir qw/module_dir/;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 12 ▶use File::Spec::Functions;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 12 ▶use IO::File;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 12 ▶use autodie qw/:file/;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 12 ▶use DBI;
Subroutine BEGIN: called CC=1 SCAR=0.0
14 12 ▶use Test::Chado::Types qw/DBH/;
Subroutine BEGIN: called CC=1 SCAR=0.0
15 12 ▶use Test::Chado;
Subroutine BEGIN: called CC=1 SCAR=0.0
16  
17 12 requires '_build_dbh', '_build_database', '_build_driver';
18 12 requires 'drop_schema', 'create_database', 'drop_database';
19 12 requires 'get_client_to_deploy', 'deploy_by_client';
20 12 requires 'is_dynamic_schema';
21  
22 12 has 'dbh' => (
23 is => 'rw',
24 isa => DBH,
25 lazy => 1,
26 builder => '_build_dbh'
27 );
28  
29 has 'dbi_attributes' => (
30 is => 'rw',
31 isa => 'HashRef',
32 lazy => 1,
33 11 ▶ default => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
34 11 my ($self) = @_;
35 11 return { AutoCommit => 1, RaiseError => 1 };
36 }
37 12 );
38  
39 12 has 'database' => (
40 is => 'rw',
41 isa => 'Str',
42 lazy => 1,
43 builder => '_build_database'
44 );
45  
46 12 has 'driver' => (
47 is => 'rw',
48 isa => 'Str',
49 lazy => 1,
50 builder => '_build_driver'
51 );
52  
53 has 'ddl' => (
54 is => 'rw',
55 isa => 'Str',
56 lazy => 1,
57 10 ▶ default => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
58 10 my ($self) = @_;
59 10 return catfile( module_dir('Test::Chado'),
60 'chado.' . lc $self->driver );
61 }
62 12 );
63  
64 12 has [qw/user password/] => ( is => 'rw', isa => 'Str' );
65 12 has 'driver_dsn' => ( is => 'rw', isa => 'Str' );
66 has 'dsn' => (
67 is => 'rw',
68 isa => 'Str',
69 0 ▶ trigger => sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
70 0 my ( $self, $value ) = @_;
71 0 my ( $scheme, $driver, $attr_str, $attr_hash, $driver_dsn )
72 = DBI->parse_dsn($value);
73 0 $self->driver($driver);
74 0 $self->driver_dsn($driver_dsn);
75 }
76 12 );
77  
78 9 ▶sub deploy_schema {
Subroutine deploy_schema: called CC=2 SCAR=7.6
Pod documented
79 9 my ($self) = @_;
80 9 ▶ if ( my $client = $self->get_client_to_deploy ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $client = $self->get_client_to_deploy) { } 0 9 9
81 0 $self->deploy_by_client($client);
82 }
83  
84 else {
85 9 $self->deploy_by_dbi;
86 }
87 }
88  
89 10 ▶sub deploy_by_dbi {
Subroutine deploy_by_dbi: called CC=3 SCAR=11.0
Pod documented
90 10 my ($self) = @_;
91 10 my $dbh = $self->dbh;
92  
93 10 my $fh = IO::File->new( $self->ddl, 'r' );
94 10 my $data = do { local ($/); <$fh> };
95 10 $fh->close();
96  
97 LINE:
98 10 foreach my $line ( split( /\n{2,}/, $data ) ) {
99 8900 ▶ next LINE if $line =~ /^\-\-/;
Branch: 1 branch
BranchTrueFalseTotal
if $line =~ /^\-\-/ 1750 7150 8900
100 7150 $line =~ s{;$}{};
101 7150 $line =~ s{/}{};
102 7150 $dbh->do($line);
103 }
104 }
105  
106 1 ▶sub reset_schema {
Subroutine reset_schema: called CC=1 SCAR=0.0
Pod documented
107 1 my ($self) = @_;
108 1 $self->drop_schema;
109 1 $self->deploy_schema;
110 }
111  
112 12 1;
113  
114 __END__
« Chado/Factory/DBManager.pm ↑ Summary Chado/DBManager/Postgression.pm »