SimpleMigration.pm

filter: Statementstmt 92.7% 51 / 55 Branchbran 50.0% 8 / 16 Conditioncond 33.3% 2 / 6 MC/DCmcdc 0.0% 0 / 4 Subroutinesub 100% 10 / 10 Podpod 0.0% 0 / 2 totaltotal 76.3% 71 / 93 CC 12 SCAR 17.9
CC
12
Cov
79%
new
11.6
apply
5.1
BEGIN
1.0
CRAP 6.0
« SimpleMigration/Client/Pg.pm ↑ Summary SimpleMigration/Migration.pm »
1 package DBIx::SimpleMigration;
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  
10 2 ▶use DBIx::SimpleMigration::Client;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 2 ▶use DBIx::SimpleMigration::Migration;
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13 2 our $VERSION = '1.0.2';
14  
15 1 ▶sub new {
Subroutine new: called CC=8 SCAR=24.5
Pod undocumented
16 1 my $self = bless {}, shift;
17 1 ▶ return unless @_ % 2 == 0;
Branch: 1 branch
BranchTrueFalseTotal
unless @_ % 2 == 0 0 1 1
18 1 my %args = @_;
19  
20 croak __PACKAGE__ . '->new: dbh option missing or not a DBI object'
21 1 ▶ unless ($args{dbh} && ref($args{dbh}) eq 'DBI::db');
Branch: 1 branch
BranchTrueFalseTotal
unless $args{"dbh"} and ref $args{"dbh"} eq "DBI::db" 0 1 1
Condition33%1/3
$args{"dbh"} and ref $args{"dbh"} eq "DBI::db"
!ll&&!rl&&r
001
MC/DC0%0/2
$args{"dbh"} and ref $args{"dbh"} eq "DBI::db"
$args{"dbh"} ref $args{"dbh"} eq "DBI::db"
Truth table33%1/3
A and B
A= $args{"dbh"}B= ref $args{"dbh"} eq "DBI::db"
ABresult
0X0
100
111
22  
23 croak __PACKAGE__ . '->new: source dir missing or does not exist'
24 1 ▶ unless ($args{source} && -d $args{source});
Branch: 1 branch
BranchTrueFalseTotal
unless $args{"source"} and -d $args{"source"} 0 1 1
Condition33%1/3
$args{"source"} and -d $args{"source"}
!ll&&!rl&&r
001
MC/DC0%0/2
$args{"source"} and -d $args{"source"}
$args{"source"} -d $args{"source"}
Truth table33%1/3
A and B
A= $args{"source"}B= -d $args{"source"}
ABresult
0X0
100
111
25  
26 1 $self->{_source} = $args{source};
27  
28 1 my %options = (
29 migrations_table => 'migrations',
30 migrations_schema => 'simplemigration',
31 );
32  
33 1 ▶ if ($args{options}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($args{"options"}) 0 1 1
34 # http://stackoverflow.com/questions/350018/how-can-i-combine-hashes-in-perl
35 0 @options{keys %{$args{options}}} = values %{$args{options}};
36 }
37 1 $self->{_options} = \%options;
38  
39 1 my $class = 'DBIx::SimpleMigration::Client::' . $args{dbh}->{Driver}->{Name};
40 1 eval "require $class; $class->import";
41 1 ▶ if ($@) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 1 1
42 0 $class = 'DBIx::SimpleMigration::Client';
43 }
44  
45 $self->{_client} = $class->new(
46 dbh => $args{dbh}->clone({
47 1 AutoCommit => 0,
48 RaiseError => 1
49 }), # new handle with AutoCommit off
50 options => \%options
51 );
52  
53 1 return $self;
54 }
55  
56 1 ▶sub apply {
Subroutine apply: called CC=5 SCAR=16.2
Pod undocumented
57 1 my ($self) = @_;
58  
59 1 ▶ if (!$self->{_client}->_migrations_table_exists) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->{"_client"}->_migrations_table_exists) 1 0 1
60 1 $self->{_client}->_create_migrations_table;
61 }
62  
63 1 my $dir = $self->{_source};
64 2 ▶ my @files = sort <$dir/*.sql>;
Subroutine BEGIN: called CC=1 SCAR=0.0
65  
66 1 my $applied_migrations = $self->{_client}->_applied_migrations;
67  
68 1 foreach my $file (@files) {
69 2 my ($filename) = fileparse($file);
70 2 ▶ next if exists $applied_migrations->{$filename};
Branch: 1 branch
BranchTrueFalseTotal
if exists $applied_migrations->{$filename} 0 2 2
71  
72 my $migration = DBIx::SimpleMigration::Migration->new(
73 client => $self->{_client},
74 2 file => $file
75 );
76  
77 2 $migration->apply;
78 }
79  
80 1 ▶ $self->{_client}->{dbh}->disconnect if $self->{_client}->{dbh};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"_client"}{"dbh"} 1 0 1
81 }
82  
83 2 1;
84  
85 __END__
« SimpleMigration/Client/Pg.pm ↑ Summary SimpleMigration/Migration.pm »