blib/lib/DBIO/DeploymentHandler/Dad.pm

filter: Statementstmt 77.2% 61 / 79 Branchbran 57.1% 16 / 28 Conditioncond 16.6% 2 / 12 MC/DCmcdc 0.0% 0 / 6 Subroutinesub 75.0% 15 / 20 Podpod 100% 10 / 10 totaltotal 67.1% 104 / 155 CC 20 SCAR 16.4
CC
20
Cov
66%
install
20.0
backup_directory
12.0
has_backup_directory
6.0
CRAP 5.1
« blib/lib/DBIO/ChangeLog/Table.pm ↑ Summary blib/lib/DBIO/Relationship/HasOne.pm »
1 package DBIO::DeploymentHandler::Dad;
2 # ABSTRACT: Parent class for DeploymentHandlers
3  
4 3 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 3 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 3 our $VERSION = '0.900007';
8  
9 3 ▶use base 'DBIO::Base';
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 3 ▶use DBIO::Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 3 ▶use DBIO::Exception;
Subroutine BEGIN: called CC=1 SCAR=0.0
13  
14 3 ▶use namespace::clean;
Subroutine BEGIN: called CC=1 SCAR=0.0
15  
16  
17 12 ▶sub new {
Subroutine new: called CC=3 SCAR=11.0
Pod documented
18 12 my ($class, @args) = @_;
19 12 ▶ my $args = @args == 1 ? $args[0] : { @args };
Branch: 1 branch
BranchTrueFalseTotal
@args == 1 ? : 10 2 12
20 12 my $self = bless({}, $class);
21 12 ▶ $self->{_dad_attrs} ||= {};
Condition50%1/2
$self->{"_dad_attrs"} ||= {}
l!l
012
MC/DC0%0/1
$self->{"_dad_attrs"} ||= {}
$self->{"_dad_attrs"}
Truth table50%1/2
A
A= $self->{"_dad_attrs"}
Aresult
11
00
22 12 %$self = (%$self, %$args);
23 12 $self;
24 }
25  
26  
27 30 ▶sub schema {
Subroutine schema: called CC=3 SCAR=16.5
Pod documented
28 30 my $self = shift;
29 30 ▶ return $self->{schema} if exists $self->{schema};
Branch: 1 branch
BranchTrueFalseTotal
if exists $self->{"schema"} 30 0 30
30 0 ▶ return $self->{_dad_attrs}{schema} if exists $self->{_dad_attrs}{schema};
Branch: 1 branch
BranchTrueFalseTotal
if exists $self->{"_dad_attrs"}{"schema"} 0 0 0
31 0 return undef;
32 }
33  
34  
35 0 ▶sub backup_directory {
Subroutine backup_directory: not called CC=3 SCAR=24.8
Pod documented
36 0 my $self = shift;
37 0 ▶ return $self->{backup_directory} if exists $self->{backup_directory};
Branch: 1 branch
BranchTrueFalseTotal
if exists $self->{"backup_directory"} 0 0 0
38 0 ▶ return $self->{_dad_attrs}{backup_directory} if exists $self->{_dad_attrs}{backup_directory};
Branch: 1 branch
BranchTrueFalseTotal
if exists $self->{"_dad_attrs"}{"backup_directory"} 0 0 0
39 0 return undef;
40 }
41  
42  
43 0 ▶sub has_backup_directory {
Subroutine has_backup_directory: not called CC=2 SCAR=17.9
Pod documented
44 0 my $self = shift;
45 0 ▶ return exists $self->{backup_directory} || exists $self->{_dad_attrs}{backup_directory};
Condition0%0/3
exists $self->{'backup_directory'} || exists $self->{'_dad_attrs'}{'backup_directory'}
l!l&&r!l&&!r
000
MC/DC0%0/2
exists $self->{'backup_directory'} || exists $self->{'_dad_attrs'}{'backup_directory'}
exists $self->{'backup_directory'} exists $self->{'_dad_attrs'}{'backup_directory'}
Truth table0%0/3
A || B
A= exists $self->{'backup_directory'}B= exists $self->{'_dad_attrs'}{'backup_directory'}
ABresult
1X1
011
000
46 }
47  
48  
49 8 ▶sub to_version {
Subroutine to_version: called CC=3 SCAR=11.0
Pod documented
50 8 my $self = shift;
51 8 ▶ return $self->{to_version} if exists $self->{to_version};
Branch: 1 branch
BranchTrueFalseTotal
if exists $self->{"to_version"} 2 6 8
52 6 my $version = $self->schema_version;
53 6 ▶ $self->{to_version} = ref($version) ? $version->numify : $version;
Branch: 1 branch
BranchTrueFalseTotal
ref $version ? : 0 6 6
54 6 return $self->{to_version};
55 }
56  
57  
58 24 ▶sub schema_version {
Subroutine schema_version: called CC=2 SCAR=6.9
Pod documented
59 24 my $self = shift;
60 24 ▶ return $self->{schema_version} if exists $self->{schema_version};
Branch: 1 branch
BranchTrueFalseTotal
if exists $self->{"schema_version"} 14 10 24
61 10 $self->{schema_version} = $self->schema->schema_version;
62 10 return $self->{schema_version};
63 }
64  
65  
66 0 ▶sub install {
Subroutine install: not called CC=4 SCAR=30.0
Pod documented
67 0 my $self = shift;
68  
69 0 ▶ my $version = (shift @_ || {})->{version} || $self->to_version;
Condition0%0/5
+(shift @_ || {})->{'version'} || $self->to_version
l!l&&r!l&&!r
000
shift @_ || {}
l!l
00
MC/DC0%0/2
+(shift @_ || {})->{'version'} || $self->to_version
shift @_ $self->to_version
Truth table0%0/3
A || B
A= shift @_B= $self->to_version
ABresult
1X1
011
000
70 0 carp "installing version $version";
71 0 ▶ DBIO::Exception->throw(
Branch: 1 branch
BranchTrueFalseTotal
if $self->version_storage_is_installed 0 0 0
72 'Install not possible as versions table already exists in database'
73 ) if $self->version_storage_is_installed;
74  
75 0 ▶ $self->txn_do(sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
76 0 my $ddl = $self->deploy({ version=> $version });
77  
78 0 $self->add_database_version({
79 version => $version,
80 ddl => $ddl,
81 });
82 0 });
83 }
84  
85  
86 2 ▶sub upgrade {
Subroutine upgrade: called CC=2 SCAR=7.0
Pod documented
87 2 carp 'upgrading';
88 2 my $self = shift;
89 2 $self->_assert_step_method('upgrade_single_step');
90 1 my $ran_once = 0;
91 1 ▶ $self->txn_do(sub {
Subroutine __ANON__: called CC=3 SCAR=11.0
92 1 ▶ while ( my $version_list = $self->next_version_set ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $version_list = $self->next_version_set) 2 1 3
93 2 $ran_once = 1;
94 my ($ddl, $upgrade_sql) = @{
95 2 ▶ $self->upgrade_single_step({ version_set => $version_list })
Condition50%1/2
$self->upgrade_single_step({'version_set', $version_list}) || []
l!l
20
MC/DC0%0/1
$self->upgrade_single_step({'version_set', $version_list}) || []
$self->upgrade_single_step({'version_set', $version_list})
Truth table50%1/2
A
A= $self->upgrade_single_step({'version_set', $version_list})
Aresult
11
00
96 ||[]};
97  
98 2 $self->add_database_version({
99 version => $version_list->[-1],
100 ddl => $ddl,
101 upgrade_sql => $upgrade_sql,
102 });
103 }
104 1 });
105  
106 1 ▶ carp 'no need to run upgrade' unless $ran_once;
Branch: 1 branch
BranchTrueFalseTotal
unless $ran_once 0 1 1
107 }
108  
109  
110 2 ▶sub downgrade {
Subroutine downgrade: called CC=2 SCAR=6.9
Pod documented
111 2 carp 'downgrading';
112 2 my $self = shift;
113 2 $self->_assert_step_method('downgrade_single_step');
114 1 my $ran_once = 0;
115 1 ▶ $self->txn_do(sub {
Subroutine __ANON__: called CC=2 SCAR=6.9
116 1 ▶ while ( my $version_list = $self->previous_version_set ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $version_list = $self->previous_version_set) 1 1 2
117 1 $ran_once = 1;
118 1 $self->downgrade_single_step({ version_set => $version_list });
119  
120 1 $self->delete_database_version({ version => $version_list->[0] });
121 }
122 1 });
123 1 ▶ carp 'no version to run downgrade' unless $ran_once;
Branch: 1 branch
BranchTrueFalseTotal
unless $ran_once 0 1 1
124 }
125  
126 # The step loops are a template: nothing DBIO ships supplies the step methods
127 # (karr k214). Refuse before the transaction opens, naming the hook, instead of
128 # dying on an unresolved method call from inside it.
129 4 ▶sub _assert_step_method {
Subroutine _assert_step_method: called CC=2 SCAR=6.9
130 4 my ($self, $method) = @_;
131 4 ▶ return if $self->can($method);
Branch: 1 branch
BranchTrueFalseTotal
if $self->can($method) 2 2 4
132 2 DBIO::Exception->throw(
133 ref($self) . " has no $method: the generic step loop of "
134 . 'DBIO::DeploymentHandler::Dad needs a subclass that supplies it '
135 . '(DBIO::DeploymentHandler replaces the loop with a native reconcile)'
136 );
137 }
138  
139  
140 0 ▶sub backup {
Subroutine backup: not called CC=1 SCAR=6.9
Pod documented
141 0 my $self = shift;
142 0 carp 'backing up';
143 0 $self->schema->storage->backup($self->backup_directory)
144 }
145  
146 3 1;
147  
148 # vim: ts=2 sw=2 expandtab
149  
150 __END__
« blib/lib/DBIO/ChangeLog/Table.pm ↑ Summary blib/lib/DBIO/Relationship/HasOne.pm »