SimpleMigration/Migration.pm

filter: Statementstmt 90.2% 46 / 51 Branchbran 43.7% 7 / 16 Conditioncond 33.3% 1 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 100% 8 / 8 Podpod 0.0% 0 / 2 totaltotal 75.6% 62 / 82 CC 11 SCAR 16.9
CC
11
Cov
77%
apply
9.0
new
6.4
BEGIN
1.0
CRAP 5.4
« SimpleMigration.pm ↑ Summary SimpleMigration/Client.pm »
1 package DBIx::SimpleMigration::Migration;
2  
3 2 ▶use 5.10.0;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 2 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 2 ▶use File::Basename;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 2 ▶use SQL::SplitStatement;
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 2 our $VERSION = '1.0.2';
12  
13 2 ▶sub new {
Subroutine new: called CC=6 SCAR=18.5
Pod undocumented
14 2 my $self = bless {}, shift;
15  
16 2 ▶ return unless @_ % 2 == 0;
Branch: 1 branch
BranchTrueFalseTotal
unless @_ % 2 == 0 0 2 2
17 2 my %args = @_;
18  
19 croak __PACKAGE__ . '->new: file option missing or does not exist'
20 2 ▶ unless ($args{file} && -f $args{file});
Branch: 1 branch
BranchTrueFalseTotal
unless $args{"file"} and -f $args{"file"} 0 2 2
Condition33%1/3
$args{"file"} and -f $args{"file"}
!ll&&!rl&&r
002
MC/DC0%0/2
$args{"file"} and -f $args{"file"}
$args{"file"} -f $args{"file"}
Truth table33%1/3
A and B
A= $args{"file"}B= -f $args{"file"}
ABresult
0X0
100
111
21  
22 2 ▶ croak __PACKAGE__ . '->new: client missing' unless $args{client};
Branch: 1 branch
BranchTrueFalseTotal
unless $args{"client"} 0 2 2
23  
24 2 $self->{_client} = $args{client};
25  
26 2 ($self->{_key}) = fileparse($args{file});
27  
28 2 my $contents;
29 {
30 2 local $/ = undef;
31 2 ▶ open FH, '<', $args{file} or croak __PACKAGE__ . '->new: Error opening file: ' . $!;
Branch: 1 branch
BranchTrueFalseTotal
open FH, "<", $args{"file"} or croak('DBIx::SimpleMigration::Migration->new: Error opening file: ' . $!) 2 0 2
32 2 $contents = <FH>;
33 2 close FH;
34 }
35  
36 2 my $splitter = SQL::SplitStatement->new;
37 2 my @statements = $splitter->split($contents);
38  
39 2 $self->{_statements} = \@statements;
40  
41 2 return $self;
42 }
43  
44 2 ▶sub apply {
Subroutine apply: called CC=6 SCAR=21.9
Pod undocumented
45 2 my ($self) = @_;
46  
47 2 say 'Applying ' . $self->{_key};
48  
49 2 ▶ if (!$self->{_client}->_lock_migrations_table) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->{"_client"}->_lock_migrations_table) 0 2 2
50 0 die 'Error acquiring table lock';
51 }
52  
53 2 eval {
54 2 foreach my $query (@{$self->{_statements}}) {
55 2 $self->{_client}->{dbh}->do($query)
56 }
57 };
58  
59 2 ▶ if ($@) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 2 2
60 0 ▶ $self->{_client}->{dbh}->rollback or croak __PACKAGE__ . '->apply: Error rolling back transaction: ' . $self->{_client}->{dbh}->errstr;
Branch: 1 branch
BranchTrueFalseTotal
$self->{"_client"}{"dbh"}->rollback or croak('DBIx::SimpleMigration::Migration->apply: Error rolling back transaction: ' . $self->{"_client"}{"dbh"}->errstr) 0 0 0
61 0 croak __PACKAGE__ . '->apply: Error applying changeset';
62 }
63  
64 2 ▶ if (!$self->{_client}->_insert_migration($self->{_key})) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->{"_client"}->_insert_migration($self->{"_key"})) 0 2 2
65 0 $self->{_client}->{dbh}->rollback;
66 0 croak;
67 }
68  
69 2 $self->{_client}->{dbh}->commit;
70 }
71  
72 2 1;
73  
74 __END__
« SimpleMigration.pm ↑ Summary SimpleMigration/Client.pm »