| 1 | package DBIx::SchemaChecksum::App::NewChangesFile; | ||
| 2 | |||
| 3 | # ABSTRACT: Generate a new changes-file | ||
| 4 | 1 | our $VERSION = '1.106'; # VERSION | |
| 5 | |||
| 6 | 1 | ▶ | use 5.010; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 7 | |||
| 8 | 1 | ▶ | use MooseX::App::Command; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 9 | 1 | extends qw(DBIx::SchemaChecksum::App); | |
| 10 | |||
| 11 | 1 | option '+sqlsnippetdir' => ( required => 1); | |
| 12 | option 'change_name' => ( | ||
| 13 | is=>'ro', | ||
| 14 | isa=>'Str', | ||
| 15 | documentation=>'Short description of the change, change file name will be based on this value', | ||
| 16 | 0 | ▶ | default=>sub { |
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||
| 17 | 0 | 'unnamed_change_'.time(), | |
| 18 | } | ||
| 19 | 1 | ); | |
| 20 | |||
| 21 | 0 | ▶ | sub run { |
|
Subroutine
run: not called CC=1 SCAR=6.9
| |||
| 22 | 0 | my $self = shift; | |
| 23 | |||
| 24 | 0 | my $name = my $change_desc = $self->change_name; | |
| 25 | 0 | $name=~s/[^a-z0-9\-\._]/_/gi; | |
| 26 | |||
| 27 | 0 | my $file = Path::Class::Dir->new($self->sqlsnippetdir)->file($name.'.sql'); | |
| 28 | 0 | my $current_checksum = $self->checksum; | |
| 29 | 0 | my $tpl = $self->tpl; | |
| 30 | 0 | $tpl=~s/%CHECKSUM%/$current_checksum/; | |
| 31 | 0 | $tpl=~s/%NAME%/$change_desc/; | |
| 32 | |||
| 33 | 0 | $file->parent->mkpath; | |
| 34 | 0 | $file->spew(iomode => '>:encoding(UTF-8)', $tpl); | |
| 35 | |||
| 36 | 0 | say "New change-file ready at ".$file->stringify; | |
| 37 | } | ||
| 38 | |||
| 39 | 0 | ▶ | sub tpl { |
|
Subroutine
tpl: not called CC=1 SCAR=6.9
| |||
| 40 | 0 | return <<EOSNIPPET; | |
| 41 | -- preSHA1sum: %CHECKSUM% | ||
| 42 | -- postSHA1sum: xxx-New-Checksum-xxx | ||
| 43 | -- %NAME% | ||
| 44 | |||
| 45 | EOSNIPPET | ||
| 46 | } | ||
| 47 | |||
| 48 | 1 | __PACKAGE__->meta->make_immutable(); | |
| 49 | 1 | 1; | |
| 50 | |||
| 51 | __END__ | ||