File Coverage

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