[Bast-commits] r7763 - in
branches/DBIx-Class-Schema-Loader/current: .
lib/DBIx/Class/Schema/Loader
ash at dev.catalyst.perl.org
ash at dev.catalyst.perl.org
Mon Oct 5 13:17:44 GMT 2009
Author: ash
Date: 2009-10-05 13:17:40 +0000 (Mon, 05 Oct 2009)
New Revision: 7763
Modified:
branches/DBIx-Class-Schema-Loader/current/Changes
branches/DBIx-Class-Schema-Loader/current/lib/DBIx/Class/Schema/Loader/Base.pm
Log:
Only redump the files when something has actually changed
Modified: branches/DBIx-Class-Schema-Loader/current/Changes
===================================================================
--- branches/DBIx-Class-Schema-Loader/current/Changes 2009-10-05 12:51:40 UTC (rev 7762)
+++ branches/DBIx-Class-Schema-Loader/current/Changes 2009-10-05 13:17:40 UTC (rev 7763)
@@ -1,5 +1,7 @@
Revision history for Perl extension DBIx::Class::Schema::Loader
+ - Only redump the files when something has actually changed
+
0.04999_08 2009-08-28
- Replace UNIVERSAL::require with Class::C3::Componentised
- Add Sybase/MSSQL support through DBD::Sybase
Modified: branches/DBIx-Class-Schema-Loader/current/lib/DBIx/Class/Schema/Loader/Base.pm
===================================================================
--- branches/DBIx-Class-Schema-Loader/current/lib/DBIx/Class/Schema/Loader/Base.pm 2009-10-05 12:51:40 UTC (rev 7762)
+++ branches/DBIx-Class-Schema-Loader/current/lib/DBIx/Class/Schema/Loader/Base.pm 2009-10-05 13:17:40 UTC (rev 7763)
@@ -265,11 +265,13 @@
if $self->{dump_overwrite};
$self->{dynamic} = ! $self->{dump_directory};
- $self->{dump_directory} ||= File::Temp::tempdir( 'dbicXXXX',
+ $self->{temp_directory} ||= File::Temp::tempdir( 'dbicXXXX',
TMPDIR => 1,
CLEANUP => 1,
);
+ $self->{dump_directory} ||= $self->{temp_directory};
+
$self->{relbuilder} = DBIx::Class::Schema::Loader::RelBuilder->new(
$self->schema, $self->inflect_plural, $self->inflect_singular
) if !$self->{skip_relationships};
@@ -398,9 +400,13 @@
if(!$self->skip_relationships) {
# The relationship loader needs a working schema
$self->{quiet} = 1;
+ local $self->{dump_directory} = $self->{temp_directory};
$self->_reload_classes(@tables);
$self->_load_relationships($_) for @tables;
$self->{quiet} = 0;
+
+ # Remove that temp dir from INC so it doesn't get reloaded
+ @INC = grep { $_ ne $self->{dump_directory} } @INC;
}
$self->_load_external($_)
@@ -529,6 +535,14 @@
}
+sub _sig_comment {
+ my ($self, $version, $ts) = @_;
+ return qq|\n\n# Created by DBIx::Class::Schema::Loader|
+ . qq| v| . $version
+ . q| @ | . $ts
+ . qq|\n# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:|;
+}
+
sub _write_classfile {
my ($self, $class, $text) = @_;
@@ -541,19 +555,28 @@
unlink($filename);
}
- my $custom_content = $self->_get_custom_content($class, $filename);
- $custom_content ||= qq|\n\n# You can replace this text with custom|
- . qq| content, and it will be preserved on regeneration|
- . qq|\n1;\n|;
+ my ($custom_content, $old_md5, $old_ver, $old_ts) = $self->_get_custom_content($class, $filename);
$text .= qq|$_\n|
for @{$self->{_dump_storage}->{$class} || []};
- $text .= qq|\n\n# Created by DBIx::Class::Schema::Loader|
- . qq| v| . $DBIx::Class::Schema::Loader::VERSION
- . q| @ | . POSIX::strftime('%Y-%m-%d %H:%M:%S', localtime)
- . qq|\n# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:|;
+ # Check and see if the dump is infact differnt
+ my $compare_to;
+ if ($old_md5) {
+ $compare_to = $text . $self->_sig_comment($old_ver, $old_ts);
+
+
+ if (Digest::MD5::md5_base64($compare_to) eq $old_md5) {
+ return;
+ }
+ }
+
+ $text .= $self->_sig_comment(
+ $DBIx::Class::Schema::Loader::VERSION,
+ POSIX::strftime('%Y-%m-%d %H:%M:%S', localtime)
+ );
+
open(my $fh, '>', $filename)
or croak "Cannot open '$filename' for writing: $!";
@@ -571,24 +594,36 @@
or croak "Error closing '$filename': $!";
}
+sub _default_custom_content {
+ return qq|\n\n# You can replace this text with custom|
+ . qq| content, and it will be preserved on regeneration|
+ . qq|\n1;\n|;
+}
+
sub _get_custom_content {
my ($self, $class, $filename) = @_;
- return if ! -f $filename;
+ return ($self->_default_custom_content) if ! -f $filename;
+
open(my $fh, '<', $filename)
or croak "Cannot open '$filename' for reading: $!";
my $mark_re =
qr{^(# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:)([A-Za-z0-9/+]{22})\n};
- my $found = 0;
my $buffer = '';
+ my ($md5, $ts, $ver);
while(<$fh>) {
- if(!$found && /$mark_re/) {
- $found = 1;
- $buffer .= $1;
+ if(!$md5 && /$mark_re/) {
+ $md5 = $2;
+ my $line = $1;
+
+ # Pull out the previous version and timestamp
+ ($ver, $ts) = $buffer =~ m/# Created by DBIx::Class::Schema::Loader v(.*?) @ (.*?)$/s;
+
+ $buffer .= $line;
croak "Checksum mismatch in '$filename'"
- if Digest::MD5::md5_base64($buffer) ne $2;
+ if Digest::MD5::md5_base64($buffer) ne $md5;
$buffer = '';
}
@@ -599,9 +634,12 @@
croak "Cannot not overwrite '$filename' without 'really_erase_my_files',"
. " it does not appear to have been generated by Loader"
- if !$found;
+ if !$md5;
- return $buffer;
+ # Default custom content:
+ $buffer ||= $self->_default_custom_content;
+
+ return ($buffer, $md5, $ver, $ts);
}
sub _use {
More information about the Bast-commits
mailing list