blib/lib/DBIx/Changeset/App/Command/update.pm

filter: Statementstmt 35.5% 38 / 107 Branchbran 14.2% 4 / 28 Conditioncond 43.1% 25 / 58 MC/DCmcdc 8.3% 2 / 24 Subroutinesub 92.8% 13 / 14 Podpod 100% 3 / 3 totaltotal 36.3% 85 / 234 CC 38 SCAR 45.4
CC
38
Cov
35%
run
156.0
options
125.7
validate
5.2
CRAP 94.1
↑ Summary blib/lib/DBIx/Changeset/App/Command/create.pm »
1 package DBIx::Changeset::App::Command::update;
2  
3 3 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 3 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 3 ▶use base qw/DBIx::Changeset::App::BaseCommand/;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 3 ▶use DBIx::Changeset::Collection;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 3 ▶use DBIx::Changeset::Loader;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 3 ▶use DBIx::Changeset::Exception;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 3 ▶use Term::Report;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 3 ▶use Term::Prompt;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 3 ▶use Data::Dumper;
Subroutine BEGIN: called CC=1 SCAR=0.0
13  
14 3 ▶use vars qw{$VERSION};
Subroutine BEGIN: called CC=1 SCAR=0.0
15 3 ▶BEGIN {
Subroutine BEGIN: called CC=1 SCAR=0.0
16 3 $VERSION = '1.11';
17 }
18  
19 =head1 NAME
20  
21 DBIx::Changeset::App::Command::update - display a list of outstanding changesets
22  
23 =head1 SYNOPSIS
24  
25 =head1 METHODS
26  
27 =head2 run
28  
29 =cut
30 0 ▶sub run {
Subroutine run: not called CC=12 SCAR=50.5
Pod documented
31 0 my ($self, $opt, $args) = @_;
32  
33 my $coll = DBIx::Changeset::Collection->new($opt->{'type'}, {
34 0 changeset_location => $opt->{'location'},
35 });
36
37 0 eval { $coll->retrieve_all(); };
38 0 my $e;
39 0 ▶ if ( $e = Exception::Class->caught() ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($e = "Exception::Class"->caught) 0 0 0
40 0 warn $e->error, "\n";
41 0 ▶ warn $e->trace->as_string, "\n" if defined $opt->{'debug'};
Branch: 1 branch
BranchTrueFalseTotal
if defined $opt->{"debug"} 0 0 0
42 0 exit;
43 }
44  
45 0 $self->determine_outstanding($opt,$coll);
46
47 0 my $rep = Term::Report->new(
48 startRow => 4,
49 numFormat => 0,
50 statusBar => [
51 label => 'Changeset Checking:',
52 subText => 'determining outstanding changesets',
53 subTextAlign => 'center',
54 showTime => 1,
55 ],
56 );
57
58 ### deal with status bar
59 0 $rep->{'statusBar'}->setItems($coll->total_outstanding);
60 0 $rep->{'statusBar'}->start;
61
62 0 $rep->savePoint('total', "Total changesets: ", 1);
63 0 $rep->savePoint('applied', "\nApplied changesets: ", 1);
64 0 $rep->savePoint('forced', "\nForced changesets: ", 1);
65  
66 0 my $total = 0;
67 0 my $applied = 0;
68 0 my $forced = 0;
69 ### create the loader object
70 0 my $loader = DBIx::Changeset::Loader->new($opt->{'loader'}, { db_host => $opt->{'db_host'}, db_name => $opt->{'db_name'}, db_pass => $opt->{'db_password'}, db_user => $opt->{'db_user'} });
71 0 $coll->reset;
72 0 ▶ while ( my $record = $coll->next_outstanding ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $record = $coll->next_outstanding) 0 0 0
73
74 0 $rep->finePrint('applied',0,++$total);
75 0 $rep->{'statusBar'}->subText($record->uri);
76 0 eval { $loader->apply_changeset($record); };
77 0 ▶ if ( $e = Exception::Class->caught('DBIx::Changeset::Exception::LoaderException') ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($e = 'Exception::Class'->caught('DBIx::Changeset::Exception::LoaderException')) { } 0 0 0
elsif ($e = 'Exception::Class'->caught) { } 0 0 0
78 0 $rep->clear();
79 0 $rep->printLine("Details of Changeset with Problems:\n");
80 0 $rep->printLine(sprintf("Id: %s\n", $record->id));
81 0 $rep->printLine(sprintf("md5: %s\n", uc($record->md5)));
82 0 $rep->printLine(sprintf("Changeset Location: %s%s\n\n", $record->changeset_location, $record->uri));
83 0 ▶ if ( $opt->{'prompt'} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($opt->{'prompt'}) { } 0 0 0
84 0 printf STDERR ("Could not apply Changeset %s because: %s\n\n", $record->uri, $e->error);
85 0 my $result = &prompt("y", "Mark changeset as Applied ?", "(y/N)", "N");
86  
87 ### reset report
88 0 $rep->clear();
89 0 $rep->{'statusBar'}->start;
90 0 $rep->savePoint('total', "Total changesets: ", 1);
91 0 $rep->savePoint('applied', "\nApplied changesets: ", 1);
92 0 $rep->savePoint('forced', "\nForced changesets: ", 1);
93  
94 0 ▶ if ( $result == 1 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($result == 1) { } 0 0 0
95 0 $record->forced(1);
96 0 $rep->finePrint('forced',0,++$forced);
97 } else {
98 0 $rep->{'statusBar'}->update;
99 0 next;
100 }
101 } else {
102 0 $rep->finish();
103 0 warn $e->error, "\n";
104 0 ▶ warn $e->trace->as_string, "\n" if defined $opt->{'debug'};
Branch: 1 branch
BranchTrueFalseTotal
if defined $opt->{"debug"} 0 0 0
105 0 exit;
106 }
107 } elsif ( $e = Exception::Class->caught() ) {
108 0 $rep->clear();
109 0 $rep->finish();
110 0 warn $e->error, "\n";
111 0 ▶ warn $e->trace->as_string, "\n" if defined $opt->{'debug'};
Branch: 1 branch
BranchTrueFalseTotal
if defined $opt->{"debug"} 0 0 0
112 0 exit;
113 }
114
115 0 $rep->finePrint('applied',0,++$applied);
116
117 ### update/create the history record
118 my $hrec = DBIx::Changeset::HistoryRecord->new({
119 history_db_dsn => $opt->{'history_db_dsn'},
120 history_db_user => $opt->{'history_db_user'},
121 0 history_db_password => $opt->{'history_db_password'},
122 });
123  
124 0 eval { $hrec->write($record); };
125  
126 0 ▶ if ( $e = Exception::Class->caught() ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($e = "Exception::Class"->caught) 0 0 0
127 0 $rep->clear();
128 0 $rep->finish();
129 0 warn $e->error, "\n";
130 0 ▶ warn $e->trace->as_string, "\n" if defined $opt->{'debug'};
Branch: 1 branch
BranchTrueFalseTotal
if defined $opt->{"debug"} 0 0 0
131 0 exit;
132 }
133  
134 0 $rep->{'statusBar'}->update;
135  
136 }
137  
138 $rep->printBarReport(
139 0 "\n\n\n\n Outstanding Changeset Summary:\n\n",
140 {
141 " Total: " => $coll->total_outstanding,
142 " Applied: " => $applied,
143 " Forced: " => $forced,
144 }
145 );
146  
147  
148 0 $rep->finish();
149  
150 0 return;
151 }
152  
153 =head2 options
154  
155 define the options for the create command
156  
157 =cut
158  
159 4 ▶sub options {
Subroutine options: called CC=23 SCAR=48.3
Pod documented
160 4 my ($self, $app) = @_;
161 return (
162 [ 'location=s' => 'Path to changeset files', { default => $app->{'config'}->{'location'} || $app->{'config'}->{'update'}->{'location'} || undef, required => 1 } ],
163 [ 'type=s' => 'Which factory to use (default disk)', { default => $app->{'config'}->{'type'} || $app->{'config'}->{'update'}->{'type'} || 'disk' } ],
164 [ 'loader=s' => 'Which loader factory to use (default mysql)', { default => $app->{'config'}->{'loader'} || $app->{'config'}->{'update'}->{'loader'} || 'mysql' } ],
165 [ 'like=s' => 'only types matching regex', { default => $app->{'config'}->{'like'} || $app->{'config'}->{'update'}->{'like'} || undef } ],
166 [ 'history_db_dsn=s' => 'DBI DSN for the history db', { default => $app->{'config'}->{'history_db_dsn'} || $app->{'config'}->{'update'}->{'history_db_dsn'} || undef, required => 1 } ],
167 [ 'history_db_user=s' => 'db user for history db', { default => $app->{'config'}->{'history_db_user'} || $app->{'config'}->{'update'}->{'history_db_user'} || undef } ],
168 [ 'history_db_password=s' => 'db password for the history db user', { default => $app->{'config'}->{'history_db_password'} || $app->{'config'}->{'update'}->{'history_db_password'} || undef } ],
169 [ 'db_name=s' => 'db name for update db', { default => $app->{'config'}->{'db_name'} || $app->{'config'}->{'update'}->{'db_name'} || undef } ],
170 [ 'db_host=s' => 'db host for update db', { default => $app->{'config'}->{'db_host'} || $app->{'config'}->{'update'}->{'db_host'} || undef } ],
171 [ 'db_user=s' => 'db user for update db', { default => $app->{'config'}->{'db_user'} || $app->{'config'}->{'update'}->{'db_user'} || undef } ],
172 4 ▶ [ 'db_password=s' => 'db password for the update db user', { default => $app->{'config'}->{'db_password'} || $app->{'config'}->{'update'}->{'db_password'} || undef } ],
Condition40%22/55
$app->{'config'}{'location'} || $app->{'config'}{'update'}{'location'} || undef
l!l
04
$app->{"config"}{"location"} or $app->{"config"}{"update"}{"location"}
l!l&&r!l&&!r
004
$app->{'config'}{'type'} || $app->{'config'}{'update'}{'type'} || 'disk'
l!l
04
$app->{"config"}{"type"} or $app->{"config"}{"update"}{"type"}
l!l&&r!l&&!r
004
$app->{'config'}{'loader'} || $app->{'config'}{'update'}{'loader'} || 'mysql'
l!l
04
$app->{"config"}{"loader"} or $app->{"config"}{"update"}{"loader"}
l!l&&r!l&&!r
004
$app->{'config'}{'like'} || $app->{'config'}{'update'}{'like'} || undef
l!l
04
$app->{"config"}{"like"} or $app->{"config"}{"update"}{"like"}
l!l&&r!l&&!r
004
$app->{'config'}{'history_db_dsn'} || $app->{'config'}{'update'}{'history_db_dsn'} || undef
l!l
04
$app->{"config"}{"history_db_dsn"} or $app->{"config"}{"update"}{"history_db_dsn"}
l!l&&r!l&&!r
004
$app->{'config'}{'history_db_user'} || $app->{'config'}{'update'}{'history_db_user'} || undef
l!l
04
$app->{"config"}{"history_db_user"} or $app->{"config"}{"update"}{"history_db_user"}
l!l&&r!l&&!r
004
$app->{'config'}{'history_db_password'} || $app->{'config'}{'update'}{'history_db_password'} || undef
l!l
04
$app->{"config"}{"history_db_password"} or $app->{"config"}{"update"}{"history_db_password"}
l!l&&r!l&&!r
004
$app->{'config'}{'db_name'} || $app->{'config'}{'update'}{'db_name'} || undef
l!l
04
$app->{"config"}{"db_name"} or $app->{"config"}{"update"}{"db_name"}
l!l&&r!l&&!r
004
$app->{'config'}{'db_host'} || $app->{'config'}{'update'}{'db_host'} || undef
l!l
04
$app->{"config"}{"db_host"} or $app->{"config"}{"update"}{"db_host"}
l!l&&r!l&&!r
004
$app->{'config'}{'db_user'} || $app->{'config'}{'update'}{'db_user'} || undef
l!l
04
$app->{"config"}{"db_user"} or $app->{"config"}{"update"}{"db_user"}
l!l&&r!l&&!r
004
$app->{'config'}{'db_password'} || $app->{'config'}{'update'}{'db_password'} || undef
l!l
04
$app->{"config"}{"db_password"} or $app->{"config"}{"update"}{"db_password"}
l!l&&r!l&&!r
004
MC/DC0%0/2
$app->{'config'}{'location'} || $app->{'config'}{'update'}{'location'} || undef
$app->{"config"}{"location"} $app->{"config"}{"update"}{"location"}
MC/DC0%0/2
$app->{'config'}{'type'} || $app->{'config'}{'update'}{'type'} || 'disk'
$app->{"config"}{"type"} $app->{"config"}{"update"}{"type"}
MC/DC0%0/2
$app->{'config'}{'loader'} || $app->{'config'}{'update'}{'loader'} || 'mysql'
$app->{"config"}{"loader"} $app->{"config"}{"update"}{"loader"}
MC/DC0%0/2
$app->{'config'}{'like'} || $app->{'config'}{'update'}{'like'} || undef
$app->{"config"}{"like"} $app->{"config"}{"update"}{"like"}
MC/DC0%0/2
$app->{'config'}{'history_db_dsn'} || $app->{'config'}{'update'}{'history_db_dsn'} || undef
$app->{"config"}{"history_db_dsn"} $app->{"config"}{"update"}{"history_db_dsn"}
MC/DC0%0/2
$app->{'config'}{'history_db_user'} || $app->{'config'}{'update'}{'history_db_user'} || undef
$app->{"config"}{"history_db_user"} $app->{"config"}{"update"}{"history_db_user"}
MC/DC0%0/2
$app->{'config'}{'history_db_password'} || $app->{'config'}{'update'}{'history_db_password'} || undef
$app->{"config"}{"history_db_password"} $app->{"config"}{"update"}{"history_db_password"}
MC/DC0%0/2
$app->{'config'}{'db_name'} || $app->{'config'}{'update'}{'db_name'} || undef
$app->{"config"}{"db_name"} $app->{"config"}{"update"}{"db_name"}
MC/DC0%0/2
$app->{'config'}{'db_host'} || $app->{'config'}{'update'}{'db_host'} || undef
$app->{"config"}{"db_host"} $app->{"config"}{"update"}{"db_host"}
MC/DC0%0/2
$app->{'config'}{'db_user'} || $app->{'config'}{'update'}{'db_user'} || undef
$app->{"config"}{"db_user"} $app->{"config"}{"update"}{"db_user"}
MC/DC0%0/2
$app->{'config'}{'db_password'} || $app->{'config'}{'update'}{'db_password'} || undef
$app->{"config"}{"db_password"} $app->{"config"}{"update"}{"db_password"}
Truth table33%1/3
A or B
A= $app->{"config"}{"location"}B= $app->{"config"}{"update"}{"location"}
ABresult
1X1
011
000
Truth table33%1/3
A or B
A= $app->{"config"}{"type"}B= $app->{"config"}{"update"}{"type"}
ABresult
1X1
011
000
Truth table33%1/3
A or B
A= $app->{"config"}{"loader"}B= $app->{"config"}{"update"}{"loader"}
ABresult
1X1
011
000
Truth table33%1/3
A or B
A= $app->{"config"}{"like"}B= $app->{"config"}{"update"}{"like"}
ABresult
1X1
011
000
Truth table33%1/3
A or B
A= $app->{"config"}{"history_db_dsn"}B= $app->{"config"}{"update"}{"history_db_dsn"}
ABresult
1X1
011
000
Truth table33%1/3
A or B
A= $app->{"config"}{"history_db_user"}B= $app->{"config"}{"update"}{"history_db_user"}
ABresult
1X1
011
000
Truth table33%1/3
A or B
A= $app->{"config"}{"history_db_password"}B= $app->{"config"}{"update"}{"history_db_password"}
ABresult
1X1
011
000
Truth table33%1/3
A or B
A= $app->{"config"}{"db_name"}B= $app->{"config"}{"update"}{"db_name"}
ABresult
1X1
011
000
Truth table33%1/3
A or B
A= $app->{"config"}{"db_host"}B= $app->{"config"}{"update"}{"db_host"}
ABresult
1X1
011
000
Truth table33%1/3
A or B
A= $app->{"config"}{"db_user"}B= $app->{"config"}{"update"}{"db_user"}
ABresult
1X1
011
000
Truth table33%1/3
A or B
A= $app->{"config"}{"db_password"}B= $app->{"config"}{"update"}{"db_password"}
ABresult
1X1
011
000
173  
174  
175 );
176 }
177  
178 =head2 validate
179  
180 define the options validation for the compare command
181  
182 =cut
183  
184 3 ▶sub validate {
Subroutine validate: called CC=5 SCAR=16.6
Pod documented
185 3 my ($self,$opt,$args) = @_;
186 3 ▶ $self->usage_error('This command requires a valid changeset location') unless ( ( defined $opt->{'location'} ) && ( -d $opt->{'location'} ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $opt->{"location"} and -d $opt->{"location"} 2 1 3
Condition100%3/3
defined $opt->{"location"} and -d $opt->{"location"}
!ll&&!rl&&r
111
MC/DC100%2/2
defined $opt->{"location"} and -d $opt->{"location"}
defined $opt->{"location"} -d $opt->{"location"}
Truth table100%3/3
A and B
A= defined $opt->{"location"}B= -d $opt->{"location"}
ABresult
0X0
100
111
187 1 ▶ $self->usage_error('This command requires a history_db_dsn') unless ( defined $opt->{'history_db_dsn'} );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $opt->{"history_db_dsn"} 0 1 1
188 1 ▶ $self->usage_error('This command requires a db_name for the db to apply changesets too') unless ( defined $opt->{'db_name'} );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $opt->{"db_name"} 1 0 1
189 0 return;
190 }
191  
192 =head1 COPYRIGHT & LICENSE
193  
194 Copyright 2004-2008 Grox Pty Ltd.
195  
196 This program is free software; you can redistribute it and/or modify it
197 under the same terms as Perl itself.
198  
199 The full text of the license can be found in the LICENSE file included with this module.
200  
201 =cut
202  
203 3 1; # End of DBIx::Changeset
↑ Summary blib/lib/DBIx/Changeset/App/Command/create.pm »