Here is an updated patch with tests for both options separately and together.
The previous version broke the backcompat tests because the regexp used to extract the version and timestamp in _parse_generated_file() was sloppy. I tightened the regexp and the code now passes all tests. I have also verified that the unmodified code fails the added tests.
See also
http://blog.des.no/?s=on+testing - I should learn to take my own advice :)
diff --git a/lib/DBIx/Class/Schema/Loader/Base.pm b/lib/DBIx/Class/Schema/Loader/Base.pm
index cbf72d8..5fb8649 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: