| 1 | 1 | ▶ | use 5.14.2; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 2 | 1 | ▶ | use Modern::Perl; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 3 | 1 | ▶ | use Moops; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||||||||||||
| 5 | 1 | ||||||||||||||||||||||||||||||||||||||
| 6 | 1 | ▶ | class DBIx::Deployer::Patch 1.2.3 { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
Subroutine
__ANON__: called CC=1 SCAR=0.0
Subroutine
__ANON__: called CC=1 SCAR=0.0
Subroutine
__ANON__: called CC=1 SCAR=0.0
Subroutine
__ANON__: called CC=1 SCAR=0.0
Subroutine
__ANON__: called CC=1 SCAR=0.0
Subroutine
__ANON__: called CC=1 SCAR=0.0
Subroutine
__ANON__: called CC=1 SCAR=0.0
Subroutine
__ANON__: called CC=1 SCAR=0.0
Subroutine
__ANON__: called CC=1 SCAR=0.0
Subroutine
__ANON__: called CC=1 SCAR=0.0
Subroutine
__ANON__: called CC=1 SCAR=0.0
Subroutine
__ANON__: called CC=1 SCAR=0.0
Subroutine
__ANON__: called CC=1 SCAR=0.0
Subroutine
__ANON__: called CC=1 SCAR=0.0
Subroutine
__ANON__: called CC=1 SCAR=0.0
Subroutine
__ANON__: called CC=1 SCAR=0.0
Subroutine
__ANON__: called CC=1 SCAR=0.0
Subroutine
__ANON__: called CC=1 SCAR=0.0
Subroutine
__ANON__: called CC=1 SCAR=0.2
| |||||||||||||||||||||||||||||||||||||||
| 7 | 1 | ▶ | use Digest::MD5; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 8 | 1 | ▶ | use Term::ANSIColor qw(colored); | ||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 9 | 1 | ▶ | use Data::Printer colored => 1; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||||||||||||
| 11 | 1 | has deployed => ( is => 'rw', isa => Bool, default => 0 ); | |||||||||||||||||||||||||||||||||||||
| 12 | 1 | has verified => ( is => 'rw', isa => Bool, default => 0 ); | |||||||||||||||||||||||||||||||||||||
| 13 | 1 | has name => ( is => 'ro', isa => Str, required => true ); | |||||||||||||||||||||||||||||||||||||
| 14 | 1 | has supports_transactions => ( is => 'ro', isa => Bool, default => true ); | |||||||||||||||||||||||||||||||||||||
| 15 | 1 | has dependencies => ( is => 'ro', isa => Maybe[ArrayRef] ); | |||||||||||||||||||||||||||||||||||||
| 16 | 1 | has deploy_sql => ( is => 'ro', isa => Maybe[Str] ); | |||||||||||||||||||||||||||||||||||||
| 17 | 1 | has deploy_sql_args => ( is => 'rw', isa => Maybe[ArrayRef] ); | |||||||||||||||||||||||||||||||||||||
| 18 | 1 | has deploy_script => ( is => 'ro', isa => Maybe[Str] ); | |||||||||||||||||||||||||||||||||||||
| 19 | 1 | has deploy_script_args => ( is => 'rw', isa => Maybe[ArrayRef] ); | |||||||||||||||||||||||||||||||||||||
| 20 | 1 | has no_verify => ( is => 'ro', isa => Bool, default => false ); | |||||||||||||||||||||||||||||||||||||
| 21 | 1 | has verify_sql => ( is => 'ro', isa => Str ); | |||||||||||||||||||||||||||||||||||||
| 22 | 1 | has verify_sql_args => ( is => 'rw', isa => ArrayRef ); | |||||||||||||||||||||||||||||||||||||
| 23 | 1 | has verify_expects => ( is => 'ro', isa => ArrayRef ); | |||||||||||||||||||||||||||||||||||||
| 24 | 1 | has db => ( is => 'ro', isa => InstanceOf['DBI::db'], required => true ); | |||||||||||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||||||||||||
| 26 | 1 | ▶ | method deploy { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
Subroutine
deploy: called CC=11 SCAR=31.2
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 27 | 13 | ▶ | if($self->deploy_sql && $self->deploy_script) { | ||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
Condition33%1/3
$self->deploy_sql and $self->deploy_script
MC/DC0%0/2
$self->deploy_sql and $self->deploy_script
$self->deploy_sql
$self->deploy_script
Truth table33%1/3
A and B
A= $self->deploy_sqlB= $self->deploy_script
| |||||||||||||||||||||||||||||||||||||||
| 28 | 0 | $self->handle_error('Patch cannot have both deploy_sql and deploy_script.'); | |||||||||||||||||||||||||||||||||||||
| 29 | } | ||||||||||||||||||||||||||||||||||||||
| 30 | elsif($self->deploy_sql) { | ||||||||||||||||||||||||||||||||||||||
| 31 | 13 | ▶ | if($self->deploy_sql_args){ | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 32 | 1 | ▶ | $self->db->do($self->deploy_sql, {}, @{ $self->deploy_sql_args }) | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 33 | or $self->handle_error($self->db->errstr); | ||||||||||||||||||||||||||||||||||||||
| 34 | } | ||||||||||||||||||||||||||||||||||||||
| 35 | else{ | ||||||||||||||||||||||||||||||||||||||
| 36 | 12 | ▶ | $self->db->do($self->deploy_sql) or $self->handle_error($self->db->errstr); | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 37 | } | ||||||||||||||||||||||||||||||||||||||
| 38 | } | ||||||||||||||||||||||||||||||||||||||
| 39 | elsif($self->deploy_script) { | ||||||||||||||||||||||||||||||||||||||
| 40 | 0 | ▶ | if( my $status = system $self->deploy_script, @{ $self->deploy_script_args || [] } ) { | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/2
$self->deploy_script_args || []
MC/DC0%0/1
$self->deploy_script_args || []
$self->deploy_script_args
Truth table0%0/2
A
A= $self->deploy_script_args
| |||||||||||||||||||||||||||||||||||||||
| 41 | 0 | $self->handle_error("Exited with status $status."); | |||||||||||||||||||||||||||||||||||||
| 42 | } | ||||||||||||||||||||||||||||||||||||||
| 43 | } | ||||||||||||||||||||||||||||||||||||||
| 44 | else { | ||||||||||||||||||||||||||||||||||||||
| 45 | 0 | $self->handle_error('Patch has neither deploy_sql nor deploy_script.'); | |||||||||||||||||||||||||||||||||||||
| 46 | } | ||||||||||||||||||||||||||||||||||||||
| 47 | } | ||||||||||||||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||||||||||||
| 49 | 1 | ▶ | before deploy { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
Subroutine
deploy: called CC=5 SCAR=17.1
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 50 | 13 | ▶ | die colored(['red'], 'Patch "' . $self->name . '" is already deployed') if $self->deployed; | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 51 | 13 | ▶ | if($self->supports_transactions && !$self->deploy_script){ $self->db->begin_work; } | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$self->supports_transactions and not $self->deploy_script
MC/DC0%0/2
$self->supports_transactions and not $self->deploy_script
$self->supports_transactions
not $self->deploy_script
Truth table33%1/3
A and not(B)
A= $self->supports_transactionsB= not $self->deploy_script
| |||||||||||||||||||||||||||||||||||||||
| 52 | } | ||||||||||||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||||||||||||
| 54 | 1 | ▶ | after deploy { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
Subroutine
deploy: called CC=2 SCAR=7.0
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 55 | 12 | $self->deployed(1); | |||||||||||||||||||||||||||||||||||||
| 56 | 12 | $self->verify; | |||||||||||||||||||||||||||||||||||||
| 57 | } | ||||||||||||||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||||||||||||
| 59 | 1 | ▶ | method verify { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
Subroutine
verify: called CC=9 SCAR=22.1
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 60 | 12 | ▶ | if($self->no_verify){ | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 61 | 1 | $self->verified(1); | |||||||||||||||||||||||||||||||||||||
| 62 | 1 | return; | |||||||||||||||||||||||||||||||||||||
| 63 | } | ||||||||||||||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||||||||||||
| 65 | 11 | ▶ | unless($self->verify_sql && @{ $self->verify_expects || [] }){ | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition80%4/5
$self->verify_sql and @{$self->verify_expects or [];}
$self->verify_expects || []
MC/DC50%1/2
$self->verify_sql and @{$self->verify_expects or [];}
$self->verify_sql
@{$self->verify_expects or [];}
MC/DC100%1/1
$self->verify_expects || []
$self->verify_expects
Truth table66%2/3
A and B
A= $self->verify_sqlB= @{$self->verify_expects or [];}
Truth table100%2/2
A
A= $self->verify_expects
| |||||||||||||||||||||||||||||||||||||||
| 66 | 1 | $self->handle_error('Patch is missing verification attributes'); | |||||||||||||||||||||||||||||||||||||
| 67 | } | ||||||||||||||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||||||||||||
| 69 | 10 | my $result; | |||||||||||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||||||||||||
| 71 | 10 | ▶ | if($self->verify_sql_args){ | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 72 | 1 | ▶ | $result = $self->db->selectall_arrayref($self->verify_sql, {}, @{ $self->verify_sql_args }) | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 73 | or $self->handle_error($self->db->errstr); | ||||||||||||||||||||||||||||||||||||||
| 74 | } | ||||||||||||||||||||||||||||||||||||||
| 75 | else{ | ||||||||||||||||||||||||||||||||||||||
| 76 | 9 | ▶ | $result = $self->db->selectall_arrayref($self->verify_sql) | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 77 | or $self->handle_error($self->db->errstr); | ||||||||||||||||||||||||||||||||||||||
| 78 | } | ||||||||||||||||||||||||||||||||||||||
| 79 | |||||||||||||||||||||||||||||||||||||||
| 80 | 10 | $self->verified($self->_check_signature($result)); | |||||||||||||||||||||||||||||||||||||
| 81 | } | ||||||||||||||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||||||||||||
| 83 | 1 | ▶ | after verify { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
Subroutine
verify: called CC=5 SCAR=16.5
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 84 | 11 | ▶ | if($self->verified){ | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 85 | 10 | ▶ | if($self->supports_transactions && !$self->deploy_script){ | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$self->supports_transactions and not $self->deploy_script
MC/DC0%0/2
$self->supports_transactions and not $self->deploy_script
$self->supports_transactions
not $self->deploy_script
Truth table33%1/3
A and not(B)
A= $self->supports_transactionsB= not $self->deploy_script
| |||||||||||||||||||||||||||||||||||||||
| 86 | 10 | $self->db->commit; | |||||||||||||||||||||||||||||||||||||
| 87 | } | ||||||||||||||||||||||||||||||||||||||
| 88 | 10 | say colored(['green'], 'Patch "' . $self->name . '" completed successfully'); | |||||||||||||||||||||||||||||||||||||
| 89 | } | ||||||||||||||||||||||||||||||||||||||
| 90 | else{ | ||||||||||||||||||||||||||||||||||||||
| 91 | 1 | $self->handle_error('Failed verification'); | |||||||||||||||||||||||||||||||||||||
| 92 | } | ||||||||||||||||||||||||||||||||||||||
| 93 | } | ||||||||||||||||||||||||||||||||||||||
| 94 | |||||||||||||||||||||||||||||||||||||||
| 95 | 1 | ▶ | method handle_error ( Str $error ){ | ||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.1
Subroutine
__ANON__: called CC=1 SCAR=0.1
Subroutine
handle_error: called CC=9 SCAR=23.3
Branch: 5 branches
| |||||||||||||||||||||||||||||||||||||||
| 96 | 3 | ▶ | if($self->supports_transactions && !$self->deploy_script){ | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$self->supports_transactions and not $self->deploy_script
MC/DC0%0/2
$self->supports_transactions and not $self->deploy_script
$self->supports_transactions
not $self->deploy_script
Truth table33%1/3
A and not(B)
A= $self->supports_transactionsB= not $self->deploy_script
| |||||||||||||||||||||||||||||||||||||||
| 97 | 3 | $self->deployed(0); | |||||||||||||||||||||||||||||||||||||
| 98 | 3 | ▶ | $self->db->rollback or die $self->name . ': ' . $self->db->errstr; | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 99 | } | ||||||||||||||||||||||||||||||||||||||
| 100 | 3 | die colored(['red'], 'Patch "' . $self->name . '" failed: ' . $error); | |||||||||||||||||||||||||||||||||||||
| 101 | } | ||||||||||||||||||||||||||||||||||||||
| 102 | |||||||||||||||||||||||||||||||||||||||
| 103 | 1 | ▶ | method _check_signature ( ArrayRef $result ){ | ||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.1
Subroutine
__ANON__: called CC=1 SCAR=0.1
Subroutine
_check_signature: called CC=7 SCAR=19.7
Branch: 5 branches
| |||||||||||||||||||||||||||||||||||||||
| 104 | 10 | my $is_equal = $self->_signature($result) eq $self->_signature($self->verify_expects); | |||||||||||||||||||||||||||||||||||||
| 105 | 10 | ▶ | unless ( $is_equal ) { | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 106 | 1 | say 'Expected:'; | |||||||||||||||||||||||||||||||||||||
| 107 | 1 | say p( $self->verify_expects ); | |||||||||||||||||||||||||||||||||||||
| 108 | 1 | say "\nReceived:"; | |||||||||||||||||||||||||||||||||||||
| 109 | 1 | say p( $result ); | |||||||||||||||||||||||||||||||||||||
| 110 | } | ||||||||||||||||||||||||||||||||||||||
| 111 | 10 | return $is_equal; | |||||||||||||||||||||||||||||||||||||
| 112 | } | ||||||||||||||||||||||||||||||||||||||
| 113 | |||||||||||||||||||||||||||||||||||||||
| 114 | 0 | ▶ | multi method _signature( HashRef $params ) { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=4.1
Subroutine
__ANON__: called CC=1 SCAR=4.1
Subroutine
_signature: not called CC=9 SCAR=39.5
Branch: 8 branches
| |||||||||||||||||||||||||||||||||||||||
| 115 | return Digest::MD5::md5_base64( | ||||||||||||||||||||||||||||||||||||||
| 116 | join( | ||||||||||||||||||||||||||||||||||||||
| 117 | '', | ||||||||||||||||||||||||||||||||||||||
| 118 | map { | ||||||||||||||||||||||||||||||||||||||
| 119 | 0 | $self->_signature($_) | |||||||||||||||||||||||||||||||||||||
| 120 | 0 | . $self->_signature( $params->{$_} ) | |||||||||||||||||||||||||||||||||||||
| 121 | } sort keys %$params | ||||||||||||||||||||||||||||||||||||||
| 122 | ) | ||||||||||||||||||||||||||||||||||||||
| 123 | ); | ||||||||||||||||||||||||||||||||||||||
| 124 | } | ||||||||||||||||||||||||||||||||||||||
| 125 | |||||||||||||||||||||||||||||||||||||||
| 126 | 0 | ▶ | multi method _signature( ArrayRef $params ) { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.6
Subroutine
__ANON__: called CC=1 SCAR=0.6
Subroutine
_signature: called CC=9 SCAR=25.9
Branch: 8 branches
| |||||||||||||||||||||||||||||||||||||||
| 127 | return Digest::MD5::md5_base64( | ||||||||||||||||||||||||||||||||||||||
| 128 | 53 | join( '', map { $self->_signature($_) } @$params ) | |||||||||||||||||||||||||||||||||||||
| 129 | ); | ||||||||||||||||||||||||||||||||||||||
| 130 | } | ||||||||||||||||||||||||||||||||||||||
| 131 | |||||||||||||||||||||||||||||||||||||||
| 132 | 0 | ▶ | multi method _signature( Str $params ) { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.6
Subroutine
__ANON__: called CC=1 SCAR=0.6
Subroutine
_signature: called CC=9 SCAR=26.2
Branch: 8 branches
| |||||||||||||||||||||||||||||||||||||||
| 133 | 147 | return Digest::MD5::md5_base64($params); | |||||||||||||||||||||||||||||||||||||
| 134 | }; | ||||||||||||||||||||||||||||||||||||||
| 135 | |||||||||||||||||||||||||||||||||||||||
| 136 | 0 | ▶ | multi method _signature ( Undef $params ) { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.6
Subroutine
__ANON__: called CC=1 SCAR=0.6
Subroutine
_signature: called CC=9 SCAR=26.2
Branch: 8 branches
| |||||||||||||||||||||||||||||||||||||||
| 137 | 28 | return; | |||||||||||||||||||||||||||||||||||||
| 138 | } | ||||||||||||||||||||||||||||||||||||||
| 139 | } | ||||||||||||||||||||||||||||||||||||||
| 140 | |||||||||||||||||||||||||||||||||||||||
| 141 | 1 | ▶ | class DBIx::Deployer 1.2.3 { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
Subroutine
__ANON__: called CC=1 SCAR=0.0
Subroutine
__ANON__: called CC=1 SCAR=0.0
Subroutine
__ANON__: called CC=1 SCAR=0.0
Subroutine
__ANON__: called CC=1 SCAR=0.0
Subroutine
__ANON__: called CC=1 SCAR=0.0
Subroutine
__ANON__: called CC=1 SCAR=0.0
Subroutine
__ANON__: called CC=1 SCAR=0.0
Subroutine
__ANON__: called CC=1 SCAR=0.0
Subroutine
__ANON__: called CC=1 SCAR=0.0
Subroutine
__ANON__: called CC=1 SCAR=0.0
Subroutine
__ANON__: called CC=1 SCAR=0.0
Subroutine
__ANON__: called CC=1 SCAR=0.0
Subroutine
__ANON__: called CC=1 SCAR=0.0
Subroutine
__ANON__: called CC=1 SCAR=0.0
Subroutine
__ANON__: called CC=1 SCAR=0.0
Subroutine
__ANON__: called CC=1 SCAR=0.0
Subroutine
__ANON__: called CC=1 SCAR=0.0
Subroutine
__ANON__: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 142 | 1 | ▶ | use DBI; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 143 | 1 | ▶ | use DBD::SQLite; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 144 | 1 | ▶ | use JSON::XS; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 145 | 1 | ▶ | use Term::ANSIColor; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 146 | 1 | ▶ | use autodie; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 147 | |||||||||||||||||||||||||||||||||||||||
| 148 | has target_db => ( is => 'lazy', isa => InstanceOf['DBI::db'], | ||||||||||||||||||||||||||||||||||||||
| 149 | builder => method { | ||||||||||||||||||||||||||||||||||||||
| 150 | die 'Missing attribute target_dsn. Optionally, you may pass a DBI::db as target_db' unless $self->target_dsn; | ||||||||||||||||||||||||||||||||||||||
| 151 | DBI->connect( | ||||||||||||||||||||||||||||||||||||||
| 152 | $self->target_dsn, | ||||||||||||||||||||||||||||||||||||||
| 153 | $self->target_username, | ||||||||||||||||||||||||||||||||||||||
| 154 | $self->target_password | ||||||||||||||||||||||||||||||||||||||
| 155 | ) or die $@; | ||||||||||||||||||||||||||||||||||||||
| 156 | 1 | } | |||||||||||||||||||||||||||||||||||||
| 157 | ); | ||||||||||||||||||||||||||||||||||||||
| 158 | |||||||||||||||||||||||||||||||||||||||
| 159 | 1 | has target_dsn => ( is => 'ro', isa => Str ); | |||||||||||||||||||||||||||||||||||||
| 160 | 1 | has target_username => ( is => 'ro', isa => Str ); | |||||||||||||||||||||||||||||||||||||
| 161 | 1 | has target_password => ( is => 'ro', isa => Str ); | |||||||||||||||||||||||||||||||||||||
| 162 | |||||||||||||||||||||||||||||||||||||||
| 163 | 1 | has patch_path => ( is => 'ro', isa => Str, required => true ); | |||||||||||||||||||||||||||||||||||||
| 164 | 1 | has deployer_db_file => ( is => 'ro', isa => Str ); | |||||||||||||||||||||||||||||||||||||
| 165 | |||||||||||||||||||||||||||||||||||||||
| 166 | has deployer_db => ( is => 'lazy', isa => InstanceOf['DBI::db'], | ||||||||||||||||||||||||||||||||||||||
| 167 | builder => method { | ||||||||||||||||||||||||||||||||||||||
| 168 | die 'Missing attribute deployer_db_file if using SQLite for patch management' unless $self->deployer_db_file; | ||||||||||||||||||||||||||||||||||||||
| 169 | my $db = DBI->connect('dbi:SQLite:dbname=' . $self->deployer_db_file) or die $@; | ||||||||||||||||||||||||||||||||||||||
| 170 | my $tables = $db->selectall_arrayref('SELECT name FROM sqlite_master WHERE type = "table"') || []; | ||||||||||||||||||||||||||||||||||||||
| 171 | |||||||||||||||||||||||||||||||||||||||
| 172 | unless(@$tables){ | ||||||||||||||||||||||||||||||||||||||
| 173 | $self->_init($db); | ||||||||||||||||||||||||||||||||||||||
| 174 | } | ||||||||||||||||||||||||||||||||||||||
| 175 | return $db; | ||||||||||||||||||||||||||||||||||||||
| 176 | 1 | } | |||||||||||||||||||||||||||||||||||||
| 177 | ); | ||||||||||||||||||||||||||||||||||||||
| 178 | |||||||||||||||||||||||||||||||||||||||
| 179 | 1 | has deployer_patch_table => ( is => 'ro', isa => Str, default => 'patches' ); | |||||||||||||||||||||||||||||||||||||
| 180 | |||||||||||||||||||||||||||||||||||||||
| 181 | has _patches_hashref => ( | ||||||||||||||||||||||||||||||||||||||
| 182 | is => 'rw', | ||||||||||||||||||||||||||||||||||||||
| 183 | isa => HashRef, | ||||||||||||||||||||||||||||||||||||||
| 184 | 12 | ▶ | default => sub{ {} } | ||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 185 | 1 | ); | |||||||||||||||||||||||||||||||||||||
| 186 | |||||||||||||||||||||||||||||||||||||||
| 187 | 1 | has supports_transactions => ( is => 'ro', isa => Bool, default => true ); | |||||||||||||||||||||||||||||||||||||
| 188 | 1 | has keep_newlines => ( is => 'ro', isa => Bool, default => false ); | |||||||||||||||||||||||||||||||||||||
| 189 | |||||||||||||||||||||||||||||||||||||||
| 190 | 1 | ▶ | method patches { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
Subroutine
patches: called CC=9 SCAR=22.1
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 191 | 18 | ▶ | return $self->_patches_hashref if %{ $self->_patches_hashref }; | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 192 | |||||||||||||||||||||||||||||||||||||||
| 193 | 10 | my $patches = $self->_patches_hashref; | |||||||||||||||||||||||||||||||||||||
| 194 | |||||||||||||||||||||||||||||||||||||||
| 195 | 10 | opendir(my $dh, $self->patch_path); | |||||||||||||||||||||||||||||||||||||
| 196 | 10 | my @patch_files = sort readdir($dh); | |||||||||||||||||||||||||||||||||||||
| 197 | 10 | closedir($dh); | |||||||||||||||||||||||||||||||||||||
| 198 | |||||||||||||||||||||||||||||||||||||||
| 199 | 10 | shift @patch_files for 1..2; # Throw away "." and ".." | |||||||||||||||||||||||||||||||||||||
| 200 | |||||||||||||||||||||||||||||||||||||||
| 201 | 10 | foreach my $file (@patch_files){ | |||||||||||||||||||||||||||||||||||||
| 202 | 12 | my $json; | |||||||||||||||||||||||||||||||||||||
| 203 | { | ||||||||||||||||||||||||||||||||||||||
| 204 | 12 | local $/ = undef; | |||||||||||||||||||||||||||||||||||||
| 205 | 12 | open(my $fh, '<', $self->patch_path . '/' . $file); | |||||||||||||||||||||||||||||||||||||
| 206 | 12 | $json = <$fh>; | |||||||||||||||||||||||||||||||||||||
| 207 | 12 | close($fh); | |||||||||||||||||||||||||||||||||||||
| 208 | } | ||||||||||||||||||||||||||||||||||||||
| 209 | 12 | ▶ | $json=~s/\n|\r\n/ /gm unless $self->keep_newlines; | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 210 | 12 | my $patch_array = JSON::XS::decode_json($json); | |||||||||||||||||||||||||||||||||||||
| 211 | 12 | foreach my $patch (@$patch_array) { | |||||||||||||||||||||||||||||||||||||
| 212 | |||||||||||||||||||||||||||||||||||||||
| 213 | my $status = $self->deployer_db->selectrow_hashref( | ||||||||||||||||||||||||||||||||||||||
| 214 | 13 | (sprintf q|SELECT * FROM %s WHERE name = ?|, $self->deployer_patch_table),{},$patch->{name}); | |||||||||||||||||||||||||||||||||||||
| 215 | |||||||||||||||||||||||||||||||||||||||
| 216 | 13 | ▶ | $self->record_patch($patch->{name}) unless $status; | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 217 | |||||||||||||||||||||||||||||||||||||||
| 218 | 13 | foreach (keys %$status) { | |||||||||||||||||||||||||||||||||||||
| 219 | 0 | $patch->{$_} = $status->{$_}; | |||||||||||||||||||||||||||||||||||||
| 220 | } | ||||||||||||||||||||||||||||||||||||||
| 221 | 13 | $patch->{db} = $self->target_db; | |||||||||||||||||||||||||||||||||||||
| 222 | 13 | $patch->{supports_transactions} = $self->supports_transactions; | |||||||||||||||||||||||||||||||||||||
| 223 | 13 | $patches->{ $patch->{name} } = DBIx::Deployer::Patch->new( %$patch ); | |||||||||||||||||||||||||||||||||||||
| 224 | } | ||||||||||||||||||||||||||||||||||||||
| 225 | } | ||||||||||||||||||||||||||||||||||||||
| 226 | 10 | $self->_patches_hashref($patches); | |||||||||||||||||||||||||||||||||||||
| 227 | 10 | return $self->_patches_hashref; | |||||||||||||||||||||||||||||||||||||
| 228 | } | ||||||||||||||||||||||||||||||||||||||
| 229 | |||||||||||||||||||||||||||||||||||||||
| 230 | 1 | ▶ | method record_patch (Str $name) { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.1
Subroutine
__ANON__: called CC=1 SCAR=0.1
Subroutine
record_patch: called CC=7 SCAR=20.1
Branch: 5 branches
| |||||||||||||||||||||||||||||||||||||||
| 231 | 13 | ▶ | $self->deployer_db->do( | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 232 | (sprintf q|INSERT INTO %s (name, deployed, verified) VALUES (?, ?, ?)|, $self->deployer_patch_table), | ||||||||||||||||||||||||||||||||||||||
| 233 | {}, $name, 0, 0) or die $@; | ||||||||||||||||||||||||||||||||||||||
| 234 | } | ||||||||||||||||||||||||||||||||||||||
| 235 | |||||||||||||||||||||||||||||||||||||||
| 236 | 1 | ▶ | method update_patch (InstanceOf['DBIx::Deployer::Patch'] $patch) { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.1
Subroutine
__ANON__: called CC=1 SCAR=0.1
Subroutine
update_patch: called CC=7 SCAR=20.1
Branch: 5 branches
| |||||||||||||||||||||||||||||||||||||||
| 237 | $self->deployer_db->do( | ||||||||||||||||||||||||||||||||||||||
| 238 | (sprintf q|UPDATE %s SET deployed = ?, verified = ? WHERE name = ?|, $self->deployer_patch_table), | ||||||||||||||||||||||||||||||||||||||
| 239 | 10 | ▶ | {}, map{ $patch->$_ } qw(deployed verified name) | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 240 | ) or die $@; | ||||||||||||||||||||||||||||||||||||||
| 241 | } | ||||||||||||||||||||||||||||||||||||||
| 242 | |||||||||||||||||||||||||||||||||||||||
| 243 | 1 | ▶ | method deploy_all { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
Subroutine
deploy_all: called CC=3 SCAR=11.0
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 244 | 8 | my $patches = $self->patches; | |||||||||||||||||||||||||||||||||||||
| 245 | 8 | foreach my $name (keys %$patches){ | |||||||||||||||||||||||||||||||||||||
| 246 | 9 | $self->deploy($patches->{$name}); | |||||||||||||||||||||||||||||||||||||
| 247 | } | ||||||||||||||||||||||||||||||||||||||
| 248 | 7 | return true; | |||||||||||||||||||||||||||||||||||||
| 249 | } | ||||||||||||||||||||||||||||||||||||||
| 250 | |||||||||||||||||||||||||||||||||||||||
| 251 | 1 | ▶ | method deploy (InstanceOf['DBIx::Deployer::Patch'] $patch) { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.1
Subroutine
__ANON__: called CC=1 SCAR=0.1
Subroutine
deploy: called CC=12 SCAR=25.0
Branch: 5 branches
| |||||||||||||||||||||||||||||||||||||||
| 252 | 13 | ▶ | return if $patch->deployed; | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 253 | |||||||||||||||||||||||||||||||||||||||
| 254 | 11 | ▶ | my @dependencies = @{ $patch->dependencies || [] }; | ||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$patch->dependencies || []
MC/DC100%1/1
$patch->dependencies || []
$patch->dependencies
Truth table100%2/2
A
A= $patch->dependencies
| |||||||||||||||||||||||||||||||||||||||
| 255 | |||||||||||||||||||||||||||||||||||||||
| 256 | 11 | ▶ | if(@dependencies){ | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 257 | 3 | my $patches = $self->patches; | |||||||||||||||||||||||||||||||||||||
| 258 | 3 | foreach my $name (@dependencies){ | |||||||||||||||||||||||||||||||||||||
| 259 | 3 | ▶ | if($patches->{$name}){ | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 260 | 2 | $self->deploy($patches->{$name}); | |||||||||||||||||||||||||||||||||||||
| 261 | } | ||||||||||||||||||||||||||||||||||||||
| 262 | else{ | ||||||||||||||||||||||||||||||||||||||
| 263 | 1 | die colored(['red'], q|Patch "| . $patch->name . qq|" failed: Patch dependency "$name" is not defined.|); | |||||||||||||||||||||||||||||||||||||
| 264 | } | ||||||||||||||||||||||||||||||||||||||
| 265 | } | ||||||||||||||||||||||||||||||||||||||
| 266 | } | ||||||||||||||||||||||||||||||||||||||
| 267 | |||||||||||||||||||||||||||||||||||||||
| 268 | 10 | eval{ $patch->deploy }; | |||||||||||||||||||||||||||||||||||||
| 269 | 10 | my $error = $@; | |||||||||||||||||||||||||||||||||||||
| 270 | 10 | $self->update_patch($patch); | |||||||||||||||||||||||||||||||||||||
| 271 | 10 | ▶ | if($error){ die $error; } | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 272 | } | ||||||||||||||||||||||||||||||||||||||
| 273 | |||||||||||||||||||||||||||||||||||||||
| 274 | 1 | ▶ | method _init (InstanceOf['DBI::db'] $db){ | ||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.1
Subroutine
__ANON__: called CC=1 SCAR=0.1
Subroutine
_init: called CC=7 SCAR=20.1
Branch: 5 branches
| |||||||||||||||||||||||||||||||||||||||
| 275 | 10 | ▶ | $db->do( | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 276 | (sprintf q|CREATE TABLE %s (name VARCHAR UNIQUE, deployed INT, verified INT)|, $self->deployer_patch_table) | ||||||||||||||||||||||||||||||||||||||
| 277 | ) or die $@; | ||||||||||||||||||||||||||||||||||||||
| 278 | } | ||||||||||||||||||||||||||||||||||||||
| 279 | } | ||||||||||||||||||||||||||||||||||||||
| 280 | |||||||||||||||||||||||||||||||||||||||
| 281 | # ABSTRACT: Light-weight database patch utility | ||||||||||||||||||||||||||||||||||||||
| 282 | # PODNAME: DBIx::Deployer | ||||||||||||||||||||||||||||||||||||||
| 283 | |||||||||||||||||||||||||||||||||||||||
| 284 | __END__ | ||||||||||||||||||||||||||||||||||||||