| File: | lib/DBIx/SchemaChecksum/App/ShowUpdatePath.pm |
| Coverage: | 95.0% |
| line | stmt | bran | cond | sub | time | code |
|---|---|---|---|---|---|---|
| 1 | package DBIx::SchemaChecksum::App::ShowUpdatePath; | |||||
| 2 | 2 2 2 | 3474 4 50 | use 5.010; | |||
| 3 | 2 2 2 | 142 14796 32 | use MooseX::App::Command; | |||
| 4 | extends qw(DBIx::SchemaChecksum::App); | |||||
| 5 | 2 2 2 | 1038187 5 389 | use Carp qw(croak); | |||
| 6 | ||||||
| 7 | option 'from_checksum' => ( is => 'ro', isa => 'Str' ); | |||||
| 8 | option '+sqlsnippetdir' => ( required => 1); | |||||
| 9 | ||||||
| 10 | sub run { | |||||
| 11 | 1 | 1890 | my $self = shift; | |||
| 12 | ||||||
| 13 | 1 | 28 | $self->show_update_path( $self->from_checksum || $self->checksum ); | |||
| 14 | } | |||||
| 15 | ||||||
| 16 | sub show_update_path { | |||||
| 17 | 5 | 7 | my ($self, $this_checksum) = @_; | |||
| 18 | 5 | 98 | my $update_path = $self->_update_path; | |||
| 19 | ||||||
| 20 | 5 | 9 | my $update = $update_path->{$this_checksum} | |||
| 21 | if ( exists $update_path->{$this_checksum} ); | |||||
| 22 | ||||||
| 23 | 5 | 7 | unless ($update) { | |||
| 24 | 1 | 7 | say "No update found that's based on $this_checksum."; | |||
| 25 | 1 | 12 | exit; | |||
| 26 | } | |||||
| 27 | ||||||
| 28 | 4 | 23 | if ( $update->[0] eq 'SAME_CHECKSUM' ) { | |||
| 29 | 2 | 5 | my ( $file, $post_checksum ) = splice( @$update, 1, 2 ); | |||
| 30 | 2 | 3 | $self->report_file($file, $post_checksum); | |||
| 31 | 2 | 429 | $self->show_update_path($post_checksum); | |||
| 32 | } | |||||
| 33 | else { | |||||
| 34 | 2 | 144 | $self->report_file($update->[0],$update->[1]); | |||
| 35 | 2 | 456 | $self->show_update_path($update->[1]); | |||
| 36 | } | |||||
| 37 | } | |||||
| 38 | ||||||
| 39 | sub report_file { | |||||
| 40 | 4 | 4 | my ($self, $file, $checksum) = @_; | |||
| 41 | 4 | 92 | say $file->relative($self->sqlsnippetdir) ." ($checksum)"; | |||
| 42 | } | |||||
| 43 | ||||||
| 44 | 1; | |||||