From: Brandon Black Date: Sun, 2 Jul 2006 18:54:38 +0000 (+0000) Subject: added new fatal error if loader_options not yet specified at clone() time X-Git-Tag: 0.03004~6 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=25328cc401d1f24e5c975475b6389fa462698b73;p=dbsrgits%2FDBIx-Class-Schema-Loader.git added new fatal error if loader_options not yet specified at clone() time Added Carp::Clan and converted a lot of dies to croaks --- diff --git a/Build.PL b/Build.PL index 7782f0f..55484fb 100644 --- a/Build.PL +++ b/Build.PL @@ -14,6 +14,7 @@ my %arguments = ( 'Class::Accessor::Fast' => 0.22, 'Class::Data::Accessor' => 0.02, 'Class::C3' => 0.11, + 'Carp::Clan' => 0, 'DBIx::Class' => 0.06003, }, recommends => { diff --git a/TODO b/TODO index 75e60e6..a72f233 100644 --- a/TODO +++ b/TODO @@ -1,6 +1,4 @@ -Better error message if no loader_options were set (see ML msg from Daniel McBrearty) - support multiple/all schemas, instead of just one support pk/uk/fk info on views, possibly. May or may not be a sane thing to try to do. diff --git a/lib/DBIx/Class/Schema/Loader.pm b/lib/DBIx/Class/Schema/Loader.pm index abbbf48..aee970d 100644 --- a/lib/DBIx/Class/Schema/Loader.pm +++ b/lib/DBIx/Class/Schema/Loader.pm @@ -4,7 +4,7 @@ use strict; use warnings; use base qw/DBIx::Class::Schema/; use base qw/Class::Data::Accessor/; -use Carp; +use Carp::Clan qw/^DBIx::Class::Schema::Loader/; use UNIVERSAL::require; use Class::C3; use Scalar::Util qw/ weaken /; @@ -147,6 +147,9 @@ See L. sub clone { my $self = shift; + croak "You failed to specify the required loader_options" + if !$self->_loader_args; + my $clone = $self->next::method(@_); $clone->_loader_args($self->_loader_args); diff --git a/lib/DBIx/Class/Schema/Loader/Base.pm b/lib/DBIx/Class/Schema/Loader/Base.pm index 3e3ccec..3272b88 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 /; @@ -317,7 +317,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: $!"; } } } @@ -328,12 +328,12 @@ sub _dump_to_dir { 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; @@ -344,20 +344,20 @@ sub _dump_to_dir { my $schema_fn = $self->_get_dump_filename($schema_class); open(my $schema_fh, '>', $schema_fn) - or die "Cannot open $schema_fn for writing: $!"; + 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); 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 +365,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"; diff --git a/lib/DBIx/Class/Schema/Loader/DBI.pm b/lib/DBIx/Class/Schema/Loader/DBI.pm index aee9314..eb20dcb 100644 --- a/lib/DBIx/Class/Schema/Loader/DBI.pm +++ b/lib/DBIx/Class/Schema/Loader/DBI.pm @@ -4,7 +4,7 @@ use strict; use warnings; use base qw/DBIx::Class::Schema::Loader::Base Class::Accessor::Fast/; use Class::C3; -use Carp; +use Carp::Clan qw/^DBIx::Class::Schema::Loader/; use UNIVERSAL::require; =head1 NAME @@ -40,7 +40,7 @@ sub new { my $subclass = 'DBIx::Class::Schema::Loader::DBI::' . $driver; $subclass->require; if($@ && $@ !~ /^Can't locate /) { - die "Failed to require $subclass: $@"; + croak "Failed to require $subclass: $@"; } elsif(!$@) { bless $self, "DBIx::Class::Schema::Loader::DBI::${driver}"; diff --git a/lib/DBIx/Class/Schema/Loader/DBI/DB2.pm b/lib/DBIx/Class/Schema/Loader/DBI/DB2.pm index b10dcef..aa6c259 100644 --- a/lib/DBIx/Class/Schema/Loader/DBI/DB2.pm +++ b/lib/DBIx/Class/Schema/Loader/DBI/DB2.pm @@ -3,6 +3,7 @@ package DBIx::Class::Schema::Loader::DBI::DB2; use strict; use warnings; use base 'DBIx::Class::Schema::Loader::DBI'; +use Carp::Clan qw/^DBIx::Class::Schema::Loader/; use Class::C3; =head1 NAME diff --git a/lib/DBIx/Class/Schema/Loader/DBI/Pg.pm b/lib/DBIx/Class/Schema/Loader/DBI/Pg.pm index a2ddb28..683a572 100644 --- a/lib/DBIx/Class/Schema/Loader/DBI/Pg.pm +++ b/lib/DBIx/Class/Schema/Loader/DBI/Pg.pm @@ -3,6 +3,7 @@ package DBIx::Class::Schema::Loader::DBI::Pg; use strict; use warnings; use base 'DBIx::Class::Schema::Loader::DBI'; +use Carp::Clan qw/^DBIx::Class::Schema::Loader/; use Class::C3; =head1 NAME diff --git a/lib/DBIx/Class/Schema/Loader/DBI/SQLite.pm b/lib/DBIx/Class/Schema/Loader/DBI/SQLite.pm index ab8bfef..fa9a057 100644 --- a/lib/DBIx/Class/Schema/Loader/DBI/SQLite.pm +++ b/lib/DBIx/Class/Schema/Loader/DBI/SQLite.pm @@ -3,8 +3,9 @@ package DBIx::Class::Schema::Loader::DBI::SQLite; use strict; use warnings; use base qw/DBIx::Class::Schema::Loader::DBI/; -use Class::C3; +use Carp::Clan qw/^DBIx::Class::Schema::Loader/; use Text::Balanced qw( extract_bracketed ); +use Class::C3; =head1 NAME @@ -105,7 +106,7 @@ sub _sqlite_parse_table { my $rcols; if($f_cols) { my @f_cols = map { s/\s*//g; lc $_ } split(/\s*,\s*/,$f_cols); - die "Mismatched column count in rel for $table => $f_table" + croak "Mismatched column count in rel for $table => $f_table" if @cols != @f_cols; $rcols = \@f_cols; } diff --git a/lib/DBIx/Class/Schema/Loader/DBI/Writing.pm b/lib/DBIx/Class/Schema/Loader/DBI/Writing.pm index 3ac5618..f21800f 100644 --- a/lib/DBIx/Class/Schema/Loader/DBI/Writing.pm +++ b/lib/DBIx/Class/Schema/Loader/DBI/Writing.pm @@ -18,6 +18,7 @@ DBIx::Class::Schema::Loader::DBI::Writing - Loader subclass writing guide for DB use strict; use warnings; use base 'DBIx::Class::Schema::Loader::DBI'; + use Carp::Clan qw/^DBIx::Class::Schema::Loader/; use Class::C3; sub _table_uniq_info { @@ -42,8 +43,8 @@ DBIx::Class::Schema::Loader::DBI::Writing - Loader subclass writing guide for DB =head1 DETAILS The only required method for new subclasses is C<_table_uniq_info>, -as I have not to date found any pseudo-standardized or DBD-agnostic -way for obtaining this information. +as there is not (yet) any standardized, DBD-agnostic way for obtaining +this information from DBI. The base DBI Loader contains generic methods that *should* work for everything else in theory, although in practice some DBDs need to diff --git a/lib/DBIx/Class/Schema/Loader/DBI/mysql.pm b/lib/DBIx/Class/Schema/Loader/DBI/mysql.pm index b83e2d5..cf2c0c9 100644 --- a/lib/DBIx/Class/Schema/Loader/DBI/mysql.pm +++ b/lib/DBIx/Class/Schema/Loader/DBI/mysql.pm @@ -3,6 +3,7 @@ package DBIx::Class::Schema::Loader::DBI::mysql; use strict; use warnings; use base 'DBIx::Class::Schema::Loader::DBI'; +use Carp::Clan qw/^DBIx::Class::Schema::Loader/; use Class::C3; =head1 NAME @@ -31,7 +32,7 @@ sub _table_fk_info { my $dbh = $self->schema->storage->dbh; my $table_def_ref = $dbh->selectrow_arrayref("SHOW CREATE TABLE $table") - or die ("Cannot get table definition for $table"); + or croak ("Cannot get table definition for $table"); my $table_def = $table_def_ref->[1] || ''; my (@reldata) = ($table_def =~ /CONSTRAINT `.*` FOREIGN KEY \(`(.*)`\) REFERENCES `(.*)` \(`(.*)`\)/ig); diff --git a/lib/DBIx/Class/Schema/Loader/RelBuilder.pm b/lib/DBIx/Class/Schema/Loader/RelBuilder.pm index faeb4b0..7cc919c 100644 --- a/lib/DBIx/Class/Schema/Loader/RelBuilder.pm +++ b/lib/DBIx/Class/Schema/Loader/RelBuilder.pm @@ -2,7 +2,7 @@ package DBIx::Class::Schema::Loader::RelBuilder; use strict; use warnings; -use Carp; +use Carp::Clan qw/^DBIx::Class::Schema::Loader/; use Lingua::EN::Inflect (); use Lingua::EN::Inflect::Number ();