File Coverage

blib/lib/App/Sqitch/Command/verify.pm
Criterion Covered Total %
statement 53 53 100.0
branch 4 4 100.0
condition 6 6 100.0
subroutine 12 12 100.0
pod 1 1 100.0
total 76 76 100.0


line stmt bran cond sub pod time code
1             package App::Sqitch::Command::verify;
2              
3 2     2   1968 use 5.010;
  2         9  
4 2     2   12 use strict;
  2         9  
  2         54  
5 2     2   12 use warnings;
  2         5  
  2         49  
6 2     2   13 use utf8;
  2         10  
  2         30  
7 2     2   59 use Moo;
  2         9  
  2         52  
8 2     2   776 use Types::Standard qw(Str HashRef);
  2         9  
  2         23  
9 2     2   1700 use App::Sqitch::X qw(hurl);
  2         4  
  2         17  
10 2     2   678 use Locale::TextDomain qw(App-Sqitch);
  2         6  
  2         22  
11 2     2   380 use List::Util qw(first);
  2         4  
  2         129  
12 2     2   15 use namespace::autoclean;
  2         13  
  2         16  
13              
14             extends 'App::Sqitch::Command';
15             with 'App::Sqitch::Role::ContextCommand';
16             with 'App::Sqitch::Role::ConnectingCommand';
17              
18             our $VERSION = 'v1.4.0'; # VERSION
19              
20             has target => (
21             is => 'ro',
22             isa => Str,
23             );
24              
25             has from_change => (
26             is => 'ro',
27             isa => Str,
28             );
29              
30             has to_change => (
31             is => 'ro',
32             isa => Str,
33             );
34              
35             has variables => (
36             is => 'ro',
37             isa => HashRef,
38             lazy => 1,
39             default => sub { {} },
40             );
41              
42             sub options {
43             return qw(
44             target|t=s
45             from-change|from=s
46             to-change|to=s
47             set|s=s%
48             );
49             }
50              
51             sub configure {
52             my ( $class, $config, $opt ) = @_;
53              
54             my %params = map {
55             $_ => $opt->{$_}
56             } grep {
57             exists $opt->{$_}
58             } qw(target from_change to_change);
59              
60             if ( my $vars = $opt->{set} ) {
61             $params{variables} = $vars;
62             }
63              
64             return \%params;
65             }
66              
67             sub _collect_vars {
68 15     15   708 my ($self, $target) = @_;
69 15         315 my $cfg = $self->sqitch->config;
70             return (
71 15         92 %{ $cfg->get_section(section => 'core.variables') },
72 15         52 %{ $cfg->get_section(section => 'deploy.variables') },
73 15         51 %{ $cfg->get_section(section => 'verify.variables') },
74 15         319 %{ $target->variables }, # includes engine
75 15         133 %{ $self->variables }, # --set
  15         641  
76             );
77             }
78              
79             sub execute {
80 10     10 1 23135 my $self = shift;
81 10         69 my ($targets, $changes) = $self->parse_args(
82             target => $self->target,
83             args => \@_,
84             );
85              
86             # Warn on multiple targets.
87 8         366 my $target = shift @{ $targets };
  8         19  
88             $self->warn(__x(
89             'Too many targets specified; connecting to {target}',
90             target => $target->name,
91 8 100       14 )) if @{ $targets };
  8         33  
92              
93             # Warn on too many changes.
94 8   100     237 my $from = $self->from_change // shift @{ $changes };
  5         15  
95 8   100     31 my $to = $self->to_change // shift @{ $changes };
  5         13  
96             $self->warn(__x(
97             'Too many changes specified; verifying from "{from}" to "{to}"',
98             from => $from,
99             to => $to,
100 8 100       13 )) if @{ $changes };
  8         27  
101              
102             # Now get to work.
103 8         821 my $engine = $target->engine;
104 8         1215 $engine->set_variables( $self->_collect_vars($target) );
105 8         175 $engine->verify($from, $to);
106 8         98 return $self;
107             }
108              
109             1;
110              
111             __END__
112              
113             =head1 Name
114              
115             App::Sqitch::Command::verify - Verify deployed Sqitch changes
116              
117             =head1 Synopsis
118              
119             my $cmd = App::Sqitch::Command::verify->new(%params);
120             $cmd->execute;
121              
122             =head1 Description
123              
124             If you want to know how to use the C<verify> command, you probably want to be
125             reading C<sqitch-verify>. But if you really want to know how the C<verify> command
126             works, read on.
127              
128             =head1 Interface
129              
130             =head2 Class Methods
131              
132             =head3 C<options>
133              
134             my @opts = App::Sqitch::Command::verify->options;
135              
136             Returns a list of L<Getopt::Long> option specifications for the command-line
137             options for the C<verify> command.
138              
139             =head2 Attributes
140              
141             =head3 C<onto_change>
142              
143             Change onto which to rebase the target.
144              
145             =head3 C<target>
146              
147             The verify target database URI.
148              
149             =head3 C<from_change>
150              
151             Change from which to verify changes.
152              
153             =head3 C<to_change>
154              
155             Change up to which to verify changes.
156              
157             =head2 Instance Methods
158              
159             =head3 C<execute>
160              
161             $verify->execute;
162              
163             Executes the verify command.
164              
165             =head1 See Also
166              
167             =over
168              
169             =item L<sqitch-verify>
170              
171             Documentation for the C<verify> command to the Sqitch command-line client.
172              
173             =item L<sqitch>
174              
175             The Sqitch command-line client.
176              
177             =back
178              
179             =head1 Author
180              
181             David E. Wheeler <david@justatheory.com>
182              
183             =head1 License
184              
185             Copyright (c) 2012-2023 iovation Inc., David E. Wheeler
186              
187             Permission is hereby granted, free of charge, to any person obtaining a copy
188             of this software and associated documentation files (the "Software"), to deal
189             in the Software without restriction, including without limitation the rights
190             to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
191             copies of the Software, and to permit persons to whom the Software is
192             furnished to do so, subject to the following conditions:
193              
194             The above copyright notice and this permission notice shall be included in all
195             copies or substantial portions of the Software.
196              
197             THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
198             IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
199             FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
200             AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
201             LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
202             OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
203             SOFTWARE.
204              
205             =cut