| 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
| |||||||||||||||||||||||||||||
| 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
Condition33%1/3
$args{"file"} and -f $args{"file"}
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"}
| |||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||
| 22 | 2 | ▶ | croak __PACKAGE__ . '->new: client missing' unless $args{client}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 60 | 0 | ▶ | $self->{_client}->{dbh}->rollback or croak __PACKAGE__ . '->apply: Error rolling back transaction: ' . $self->{_client}->{dbh}->errstr; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 61 | 0 | croak __PACKAGE__ . '->apply: Error applying changeset'; | |||||||||||||||||||||||||||
| 62 | } | ||||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||
| 64 | 2 | ▶ | if (!$self->{_client}->_insert_migration($self->{_key})) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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__ | ||||||||||||||||||||||||||||