X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FDBIx%2FClass%2FSchema%2FLoader%2FBase.pm;h=a260f35897df430267a9941fa1c8aaf8db0cb86b;hb=d65cda9ebaebbf4b6e0e7a9bb9ba20c919afb55c;hp=3e3ccecc901b7d9c9b95acac6bc418d347ea38d3;hpb=483987b9e98a876bf0348c32e13aecbb58521afc;p=dbsrgits%2FDBIx-Class-Schema-Loader.git diff --git a/lib/DBIx/Class/Schema/Loader/Base.pm b/lib/DBIx/Class/Schema/Loader/Base.pm index 3e3ccec..a260f35 100644 --- a/lib/DBIx/Class/Schema/Loader/Base.pm +++ b/lib/DBIx/Class/Schema/Loader/Base.pm @@ -4,7 +4,7 @@ use strict; use warnings; use base qw/Class::Accessor::Fast/; use Class::C3; -use Carp; +use Carp::Clan qw/^DBIx::Class::Schema::Loader/; use UNIVERSAL::require; use DBIx::Class::Schema::Loader::RelBuilder; use Data::Dump qw/ dump /; @@ -28,6 +28,7 @@ __PACKAGE__->mk_ro_accessors(qw/ inflect_plural debug dump_directory + dump_overwrite legacy_default_inflections @@ -64,6 +65,12 @@ Try to automatically detect/setup has_a and has_many relationships. If set to true, each constructive L statement the loader decides to execute will be C-ed before execution. +=head2 db_schema + +Set the name of the schema to load (schema in the sense that your database +vendor means it). Does not currently support loading more than one schema +name. + =head2 constraint Only load tables matching regex. Best specified as a qr// regex. @@ -138,6 +145,10 @@ your existing code if you started developing on a version prior to 0.03 and don't wish to go around updating all your relationship names to the new defaults. +This option will continue to be supported until at least version 0.05xxx, +but may dissappear sometime thereafter. It is recommended that you update +your code to use the newer-style inflections when you have the time. + =head2 dump_directory This option is designed to be a tool to help you transition from this @@ -162,8 +173,16 @@ is meant for one-time manual usage. See L for examples of the 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. + =head1 DEPRECATED CONSTRUCTOR OPTIONS +B + =head2 inflect_map Equivalent to L. @@ -177,7 +196,7 @@ Equivalent to L. You connect these schemas the same way you would any L, which is by calling either C or C on a schema class or object. These options are only supported via the deprecated -C interface, which will be removed in the future. +C interface, which is also being removed in 0.04000. =head1 METHODS @@ -230,7 +249,8 @@ sub new { # Support deprecated arguments for(qw/inflect_map inflect/) { warn "Argument $_ is deprecated in favor of 'inflect_plural'" - if $self->{$_}; + . ", and will be removed in 0.04000" + if $self->{$_}; } $self->{inflect_plural} ||= $self->{inflect_map} || $self->{inflect}; @@ -317,7 +337,7 @@ sub _ensure_dump_subdirs { foreach (@name_parts) { $dir .= q{/} . $_; if(! -d $dir) { - mkdir($dir) or die "mkdir('$dir') failed: $!"; + mkdir($dir) or croak "mkdir('$dir') failed: $!"; } } } @@ -326,14 +346,15 @@ sub _dump_to_dir { my ($self) = @_; my $target_dir = $self->dump_directory; + my $schema_class = $self->schema_class; - die "Must specify target directory for dumping!" if ! $target_dir; + croak "Must specify target directory for dumping!" if ! $target_dir; warn "Dumping manual schema for $schema_class to directory $target_dir ...\n"; if(! -d $target_dir) { - mkdir($target_dir) or die "mkdir('$target_dir') failed: $!"; + mkdir($target_dir) or croak "mkdir('$target_dir') failed: $!"; } my $verstr = $DBIx::Class::Schema::Loader::VERSION; @@ -343,21 +364,25 @@ sub _dump_to_dir { $self->_ensure_dump_subdirs($schema_class); my $schema_fn = $self->_get_dump_filename($schema_class); - open(my $schema_fh, '>', $schema_fn) - or die "Cannot open $schema_fn for writing: $!"; + croak "$schema_fn exists, will not overwrite" + if -f $schema_fn && !$self->dump_overwrite; + sysopen(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 die "Cannot close $schema_fn: $!"; + 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; open(my $src_fh, '>', $src_fn) - or die "Cannot open $src_fn for writing: $!"; + or croak "Cannot open $src_fn for writing: $!"; print $src_fh qq|package $src_class;\n\n$tagline\n\n|; print $src_fh qq|use strict;\nuse warnings;\n\n|; print $src_fh qq|use base 'DBIx::Class';\n\n|; @@ -365,7 +390,7 @@ sub _dump_to_dir { for @{$self->{_dump_storage}->{$src_class}}; print $src_fh qq|\n1;\n\n|; close($src_fh) - or die "Cannot close $src_fn: $!"; + or croak "Cannot close $src_fn: $!"; } warn "Schema dump completed.\n";