| 1 | package DBIx::SchemaChecksum::App::ShowUpdatePath; | ||||||||||||||||||||
| 2 | |||||||||||||||||||||
| 3 | # ABSTRACT: Show the update path | ||||||||||||||||||||
| 4 | 2 | our $VERSION = '1.106'; # VERSION | |||||||||||||||||||
| 5 | |||||||||||||||||||||
| 6 | 2 | ▶ | use 5.010; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 7 | |||||||||||||||||||||
| 8 | 2 | ▶ | use MooseX::App::Command; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 9 | 2 | extends qw(DBIx::SchemaChecksum::App); | |||||||||||||||||||
| 10 | 2 | ▶ | use Carp qw(croak); | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 11 | 2 | ▶ | use Moose::Util::TypeConstraints; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 12 | |||||||||||||||||||||
| 13 | 2 | option 'from_checksum' => ( is => 'ro', isa => 'Str',documentation => q[start update path from this checksum] | |||||||||||||||||||
| 14 | ); | ||||||||||||||||||||
| 15 | 2 | option 'output' => ( is => 'ro', default=>'nice',isa=>enum([qw[ nice concat psql ]]),); | |||||||||||||||||||
| 16 | 2 | option 'dbname' => ( is=>'ro', isa=>'Str', default=>'datebase_name'); | |||||||||||||||||||
| 17 | 2 | option '+sqlsnippetdir' => ( required => 1); | |||||||||||||||||||
| 18 | |||||||||||||||||||||
| 19 | 2 | has '_concat' => (is=>'rw',isa=>'Str', default=>''); | |||||||||||||||||||
| 20 | |||||||||||||||||||||
| 21 | 1 | ▶ | sub run { | ||||||||||||||||||
|
Subroutine
run: called CC=2 SCAR=8.1
| |||||||||||||||||||||
| 22 | 1 | my $self = shift; | |||||||||||||||||||
| 23 | |||||||||||||||||||||
| 24 | 1 | ▶ | $self->show_update_path( $self->from_checksum || $self->checksum ); | ||||||||||||||||||
|
Condition33%1/3
$self->from_checksum || $self->checksum
MC/DC0%0/2
$self->from_checksum || $self->checksum
$self->from_checksum
$self->checksum
Truth table33%1/3
A || B
A= $self->from_checksumB= $self->checksum
| |||||||||||||||||||||
| 25 | |||||||||||||||||||||
| 26 | } | ||||||||||||||||||||
| 27 | |||||||||||||||||||||
| 28 | 5 | ▶ | sub show_update_path { | ||||||||||||||||||
|
Subroutine
show_update_path: called CC=6 SCAR=18.0
| |||||||||||||||||||||
| 29 | 5 | my ($self, $this_checksum) = @_; | |||||||||||||||||||
| 30 | 5 | my $update_path = $self->_update_path; | |||||||||||||||||||
| 31 | |||||||||||||||||||||
| 32 | my $update = $update_path->{$this_checksum} | ||||||||||||||||||||
| 33 | 5 | ▶ | if ( exists $update_path->{$this_checksum} ); | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 34 | |||||||||||||||||||||
| 35 | 5 | ▶ | unless ($update) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 36 | 1 | ▶ | print "# " if $self->output eq 'psql'; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 37 | 1 | ▶ | print "-- " if $self->output eq 'concat'; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 38 | 1 | say "No update found that's based on $this_checksum."; | |||||||||||||||||||
| 39 | 1 | return; | |||||||||||||||||||
| 40 | } | ||||||||||||||||||||
| 41 | |||||||||||||||||||||
| 42 | 4 | ▶ | if ( $update->[0] eq 'SAME_CHECKSUM' ) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 43 | 2 | my ( $file, $post_checksum ) = splice( @$update, 1, 2 ); | |||||||||||||||||||
| 44 | 2 | $self->report_file($file, $post_checksum); | |||||||||||||||||||
| 45 | 2 | $self->show_update_path($post_checksum); | |||||||||||||||||||
| 46 | } | ||||||||||||||||||||
| 47 | else { | ||||||||||||||||||||
| 48 | 2 | $self->report_file($update->[0],$update->[1]); | |||||||||||||||||||
| 49 | 2 | $self->show_update_path($update->[1]); | |||||||||||||||||||
| 50 | } | ||||||||||||||||||||
| 51 | } | ||||||||||||||||||||
| 52 | |||||||||||||||||||||
| 53 | 4 | ▶ | sub report_file { | ||||||||||||||||||
|
Subroutine
report_file: called CC=4 SCAR=20.9
| |||||||||||||||||||||
| 54 | 4 | my ($self, $file, $checksum) = @_; | |||||||||||||||||||
| 55 | |||||||||||||||||||||
| 56 | 4 | ▶ | if ($self->output eq 'nice') { | ||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||
| 57 | 4 | say $file->relative($self->sqlsnippetdir) ." ($checksum)"; | |||||||||||||||||||
| 58 | } | ||||||||||||||||||||
| 59 | elsif ($self->output eq 'psql') { | ||||||||||||||||||||
| 60 | 0 | say 'psql '.$self->dbname.' -1 -f '.$file->relative($self->sqlsnippetdir); | |||||||||||||||||||
| 61 | } | ||||||||||||||||||||
| 62 | elsif ($self->output eq 'concat') { | ||||||||||||||||||||
| 63 | 0 | say "\n-- file: ".$file->relative($self->sqlsnippetdir)."\n".join('',$file->slurp)."\n"; | |||||||||||||||||||
| 64 | } | ||||||||||||||||||||
| 65 | } | ||||||||||||||||||||
| 66 | |||||||||||||||||||||
| 67 | 2 | __PACKAGE__->meta->make_immutable(); | |||||||||||||||||||
| 68 | 2 | 1; | |||||||||||||||||||
| 69 | |||||||||||||||||||||
| 70 | __END__ | ||||||||||||||||||||