From: Brandon Black Date: Tue, 18 Jul 2006 13:39:37 +0000 (+0000) Subject: dump code now skips+warns instead of dies when dump_overwrite not set [from nilsonsfj] X-Git-Tag: 0.03005~2 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=02356864b0d0bcdf0716a4adfd0a69c8360fe00d;p=dbsrgits%2FDBIx-Class-Schema-Loader.git dump code now skips+warns instead of dies when dump_overwrite not set [from nilsonsfj] --- diff --git a/Build.PL b/Build.PL index 55484fb..032aaaf 100644 --- a/Build.PL +++ b/Build.PL @@ -27,6 +27,7 @@ my %arguments = ( }, build_requires => { 'Test::More' => 0.32, + 'Test::Warn' => 0.08, 'DBI' => 1.50, 'DBD::SQLite' => 1.12, }, diff --git a/Changes b/Changes index 0c3f8cf..a08ec01 100644 --- a/Changes +++ b/Changes @@ -1,5 +1,8 @@ Revision history for Perl extension DBIx::Class::Schema::Loader + - dump code now skips+warns instead of dies when + dump_overwrite not set [from nilsonsfj] + 0.03004 Tue Jul 11 04:38:09 UTC 2006 - make_schema_at efficiency improvements - improved debugging output diff --git a/lib/DBIx/Class/Schema/Loader.pm b/lib/DBIx/Class/Schema/Loader.pm index b3cd945..f54c5a7 100644 --- a/lib/DBIx/Class/Schema/Loader.pm +++ b/lib/DBIx/Class/Schema/Loader.pm @@ -12,7 +12,7 @@ use Scalar::Util qw/ weaken /; # Always remember to do all digits for the version even if they're 0 # i.e. first release of 0.XX *must* be 0.XX000. This avoids fBSD ports # brain damage and presumably various other packaging systems too -our $VERSION = '0.03004'; +our $VERSION = '0.03005'; __PACKAGE__->mk_classaccessor('dump_to_dir'); __PACKAGE__->mk_classaccessor('loader'); diff --git a/lib/DBIx/Class/Schema/Loader/Base.pm b/lib/DBIx/Class/Schema/Loader/Base.pm index d4a7918..dff4419 100644 --- a/lib/DBIx/Class/Schema/Loader/Base.pm +++ b/lib/DBIx/Class/Schema/Loader/Base.pm @@ -176,8 +176,8 @@ recommended way to access this functionality. =head2 dump_overwrite If set to a true value, the dumping code will overwrite existing files. -The default is false, which means the dumping code will die if it encounters -an existing file. +The default is false, which means the dumping code will skip the already +existing files. =head1 DEPRECATED CONSTRUCTOR OPTIONS @@ -364,23 +364,28 @@ sub _dump_to_dir { $self->_ensure_dump_subdirs($schema_class); my $schema_fn = $self->_get_dump_filename($schema_class); - croak "$schema_fn exists, will not overwrite" - if -f $schema_fn && !$self->dump_overwrite; - open(my $schema_fh, '>', $schema_fn) - or croak "Cannot open $schema_fn for writing: $!"; - print $schema_fh qq|package $schema_class;\n\n$tagline\n\n|; - print $schema_fh qq|use strict;\nuse warnings;\n\n|; - print $schema_fh qq|use base 'DBIx::Class::Schema';\n\n|; - print $schema_fh qq|__PACKAGE__->load_classes;\n|; - print $schema_fh qq|\n1;\n\n|; - close($schema_fh) - or croak "Cannot close $schema_fn: $!"; + if (-f $schema_fn && !$self->dump_overwrite) { + warn "$schema_fn exists, will not overwrite\n"; + } + else { + open(my $schema_fh, '>', $schema_fn) + or croak "Cannot open $schema_fn for writing: $!"; + print $schema_fh qq|package $schema_class;\n\n$tagline\n\n|; + print $schema_fh qq|use strict;\nuse warnings;\n\n|; + print $schema_fh qq|use base 'DBIx::Class::Schema';\n\n|; + print $schema_fh qq|__PACKAGE__->load_classes;\n|; + print $schema_fh qq|\n1;\n\n|; + close($schema_fh) + or croak "Cannot close $schema_fn: $!"; + } foreach my $src_class (sort keys %{$self->{_dump_storage}}) { $self->_ensure_dump_subdirs($src_class); my $src_fn = $self->_get_dump_filename($src_class); - croak "$src_fn exists, will not overwrite" - if -f $src_fn && !$self->dump_overwrite; + if (-f $src_fn && !$self->dump_overwrite) { + warn "$src_fn exists, will not overwrite\n"; + next; + } open(my $src_fh, '>', $src_fn) or croak "Cannot open $src_fn for writing: $!"; print $src_fh qq|package $src_class;\n\n$tagline\n\n|; diff --git a/t/22dump.t b/t/22dump.t index 54193d9..b01ce1c 100644 --- a/t/22dump.t +++ b/t/22dump.t @@ -1,5 +1,6 @@ use strict; use Test::More; +use Test::Warn; use lib qw(t/lib); use File::Path; use make_dbictest_db; @@ -33,17 +34,23 @@ eval { DBICTest::Schema::1->connect($make_dbictest_db::dsn) }; ok(!$@, 'no death with dump_directory set') or diag "Dump failed: $@"; DBICTest::Schema::1->loader(undef); -eval { DBICTest::Schema::1->connect($make_dbictest_db::dsn) }; -like($@, qr|DBICTest/Schema/1.pm exists, will not overwrite|, - 'death when attempting to overwrite without option'); +warnings_like { DBICTest::Schema::1->connect($make_dbictest_db::dsn) } + [ + qr|Dumping manual schema|, + (qr|DBICTest/Schema/1.*?.pm exists, will not overwrite|) x 3, + qr|Schema dump completed| + ], + 'warn and skip when attempting to overwrite without option'; rmtree($dump_path, 1, 0711); eval { DBICTest::Schema::2->connect($make_dbictest_db::dsn) }; -ok(!$@, 'no death with dump_directory set (overwrite1)') or diag "Dump failed: $@"; +ok(!$@, 'no death with dump_directory set (overwrite1)') + or diag "Dump failed: $@"; DBICTest::Schema::2->loader(undef); eval { DBICTest::Schema::2->connect($make_dbictest_db::dsn) }; -ok(!$@, 'no death with dump_directory set (overwrite2)') or diag "Dump failed: $@"; +ok(!$@, 'no death with dump_directory set (overwrite2)') + or diag "Dump failed: $@"; -END { rmtree($dump_path, 1, 0711); } +END { rmtree($dump_path, 1, 1); }