File Coverage

lib/DBIx/SchemaChecksum/App/NewChangesFile.pm
Criterion Covered Total %
statement 5 17 29.4
branch n/a
condition n/a
subroutine 2 4 50.0
pod n/a
total 7 21 33.3


line stmt bran cond sub pod time code
1             package DBIx::SchemaChecksum::App::NewChangesFile;
2 1     1   1280 use 5.010;
  1         4  
3              
4             # ABSTRACT: Generate a new changes-file
5              
6 1     1   6 use MooseX::App::Command;
  1         2  
  1         10  
7             extends qw(DBIx::SchemaChecksum::App);
8              
9             option '+sqlsnippetdir' => ( required => 1);
10             option 'change_name' => (
11             is=>'ro',
12             isa=>'Str',
13             documentation=>'Short description of the change, change file name will be based on this value',
14             default=>sub {
15             'unnamed_change_'.time(),
16             }
17             );
18              
19             sub run {
20 0     0     my $self = shift;
21              
22 0           my $name = my $change_desc = $self->change_name;
23 0           $name=~s/[^a-z0-9\-\._]/_/gi;
24              
25 0           my $file = Path::Class::Dir->new($self->sqlsnippetdir)->file($name.'.sql');
26 0           my $current_checksum = $self->checksum;
27 0           my $tpl = $self->tpl;
28 0           $tpl=~s/%CHECKSUM%/$current_checksum/;
29 0           $tpl=~s/%NAME%/$change_desc/;
30              
31 0           $file->parent->mkpath;
32 0           $file->spew(iomode => '>:encoding(UTF-8)', $tpl);
33              
34 0           say "New change-file ready at ".$file->stringify;
35             }
36              
37             sub tpl {
38 0     0     return <<EOSNIPPET;
39             -- preSHA1sum: %CHECKSUM%
40             -- postSHA1sum: xxx-New-Checksum-xxx
41             -- %NAME%
42              
43             EOSNIPPET
44             }
45              
46             __PACKAGE__->meta->make_immutable();
47             1;
48              
49             __END__
50              
51             =pod
52              
53             =encoding UTF-8
54              
55             =head1 NAME
56              
57             DBIx::SchemaChecksum::App::NewChangesFile - Generate a new changes-file
58              
59             =head1 VERSION
60              
61             version 1.102
62              
63             =head1 DESCRIPTION
64              
65             Generate a new, empty changes file template in C<sqlsnippetdir> with
66             the current checksum autofilled in. You can provide a
67             C<--change_name>, which will be used to generate the filename, and
68             will be stored as a comment inside the file. If you do not specify the
69             C<change_name>, defaults to C<unnamed_change_EPOCH>.
70              
71             =head1 AUTHORS
72              
73             =over 4
74              
75             =item *
76              
77             Thomas Klausner <domm@cpan.org>
78              
79             =item *
80              
81             MaroÅ¡ Kollár <maros@cpan.org>
82              
83             =item *
84              
85             Klaus Ita <koki@worstofall.com>
86              
87             =back
88              
89             =head1 COPYRIGHT AND LICENSE
90              
91             This software is copyright (c) 2012 by Thomas Klausner, MaroÅ¡ Kollár, Klaus Ita.
92              
93             This is free software; you can redistribute it and/or modify it under
94             the same terms as the Perl 5 programming language system itself.
95              
96             =cut