From: Dag-Erling Smørgrav Date: Fri, 4 Apr 2014 13:26:27 +0000 (+0100) Subject: Add options to omit the version and timestamp from the generated code (RT#92300) X-Git-Tag: 0.07040~11 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=c43d9f4771f4e6bb3964676d7fbfd0a251e02194;p=dbsrgits%2FDBIx-Class-Schema-Loader.git Add options to omit the version and timestamp from the generated code (RT#92300) --- diff --git a/Changes b/Changes index 545c311..39c3788 100644 --- a/Changes +++ b/Changes @@ -1,5 +1,8 @@ Revision history for Perl extension DBIx::Class::Schema::Loader + - Add options to omit the version and timestamp from the + generated code (RT#92300) + 0.07039 2014-01-06 - Fix table listing with DBD::DB2 >= 1.85 (RT#91764) - Add accessor for the list of (re)generated classes diff --git a/lib/DBIx/Class/Schema/Loader/Base.pm b/lib/DBIx/Class/Schema/Loader/Base.pm index cbf72d8..03ccea6 100644 --- a/lib/DBIx/Class/Schema/Loader/Base.pm +++ b/lib/DBIx/Class/Schema/Loader/Base.pm @@ -63,6 +63,8 @@ __PACKAGE__->mk_group_ro_accessors('simple', qw/ overwrite_modifications dry_run generated_classes + omit_version + omit_timestamp relationship_attrs @@ -860,6 +862,14 @@ made to Loader-generated code. Again, you should be using version control on your schema classes. Be careful with this option. +=head2 omit_version + +Omit the package version from the signature comment. + +=head2 omit_timestamp + +Omit the creation timestamp from the signature comment. + =head2 custom_column_info Hook for adding extra attributes to the @@ -2031,8 +2041,8 @@ sub _dump_to_dir { sub _sig_comment { my ($self, $version, $ts) = @_; return qq|\n\n# Created by DBIx::Class::Schema::Loader| - . qq| v| . $version - . q| @ | . $ts + . (defined($version) ? q| v| . $version : '') + . (defined($ts) ? q| @ | . $ts : '') . qq|\n# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:|; } @@ -2154,8 +2164,8 @@ sub _write_classfile { return if $self->dry_run; $text .= $self->_sig_comment( - $self->version_to_dump, - POSIX::strftime('%Y-%m-%d %H:%M:%S', localtime) + $self->omit_version ? undef : $self->version_to_dump, + $self->omit_timestamp ? undef : POSIX::strftime('%Y-%m-%d %H:%M:%S', localtime) ); open(my $fh, '>:encoding(UTF-8)', $filename) @@ -2214,7 +2224,9 @@ sub _parse_generated_file { $md5 = $2; # Pull out the version and timestamp from the line above - ($ver, $ts) = $gen =~ m/^# Created by DBIx::Class::Schema::Loader v(.*?) @ (.*?)\r?\Z/m; + ($ver, $ts) = $gen =~ m/^# Created by DBIx::Class::Schema::Loader( v[\d.]+)?( @ [\d-]+ [\d:]+)?\r?\Z/m; + $ver =~ s/^ v// if $ver; + $ts =~ s/^ @ // if $ts; $gen .= $pre_md5; croak "Checksum mismatch in '$fn', the auto-generated part of the file has been modified outside of this loader. Aborting.\nIf you want to overwrite these modifications, set the 'overwrite_modifications' loader option.\n" diff --git a/t/23dumpmore.t b/t/23dumpmore.t index 47364f5..dd52596 100644 --- a/t/23dumpmore.t +++ b/t/23dumpmore.t @@ -599,5 +599,46 @@ ok( !-e $schema_file, "dry-run doesn't create file for schema class" ); (my $schema_dir = $schema_file) =~ s/\.pm\z//; ok( !-e $schema_dir, "dry-run doesn't create subdirectory for schema namespace" ); +# test omit_version (RT#92300) +$t->dump_test( + classname => 'DBICTest::DumpMore::omit_version', + options => { + omit_version => 1, + }, + regexes => { + Foo => [ + qr/^\# Created by DBIx::Class::Schema::Loader @ \d\d\d\d-\d\d-\d\d \d\d:\d\d:\d\d$/m, + ], + }, +); + +# test omit_timestamp (RT#92300) +$t->dump_test( + classname => 'DBICTest::DumpMore::omit_timestamp', + options => { + omit_timestamp => 1, + }, + regexes => { + Foo => [ + qr/^\# Created by DBIx::Class::Schema::Loader v[\d.]+$/m, + ], + }, +); + +# test omit_version and omit_timestamp simultaneously (RT#92300) +$t->dump_test( + classname => 'DBICTest::DumpMore::omit_both', + options => { + omit_version => 1, + omit_timestamp => 1, + }, + # A positive regex here would match the top comment + neg_regexes => { + Foo => [ + qr/^\# Created by DBIx::Class::Schema::Loader.+$/m, + ], + }, +); + done_testing; # vim:et sts=4 sw=4 tw=0: