From: Robert Buels Date: Sat, 14 Aug 2010 00:18:55 +0000 (-0700) Subject: clean up relbuilder choosing code X-Git-Tag: 0.07002~24 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=ef372cf411c15be6c7ab1232f4134ec47f3ef9bb;p=dbsrgits%2FDBIx-Class-Schema-Loader.git clean up relbuilder choosing code --- diff --git a/lib/DBIx/Class/Schema/Loader/Base.pm b/lib/DBIx/Class/Schema/Loader/Base.pm index 1219e91..d469f6c 100644 --- a/lib/DBIx/Class/Schema/Loader/Base.pm +++ b/lib/DBIx/Class/Schema/Loader/Base.pm @@ -973,26 +973,26 @@ sub rescan { } sub _relbuilder { - no warnings 'uninitialized'; my ($self) = @_; return if $self->{skip_relationships}; - if ($self->naming->{relationships} eq 'v4') { - require DBIx::Class::Schema::Loader::RelBuilder::Compat::v0_040; - return $self->{relbuilder} ||= - DBIx::Class::Schema::Loader::RelBuilder::Compat::v0_040->new( $self ); - } - elsif ($self->naming->{relationships} eq 'v5') { - require DBIx::Class::Schema::Loader::RelBuilder::Compat::v0_05; - return $self->{relbuilder} ||= DBIx::Class::Schema::Loader::RelBuilder::Compat::v0_05->new( $self ); - } - elsif ($self->naming->{relationships} eq 'v6') { - require DBIx::Class::Schema::Loader::RelBuilder::Compat::v0_06; - return $self->{relbuilder} ||= DBIx::Class::Schema::Loader::RelBuilder::Compat::v0_06->new( $self ); - } + return $self->{relbuilder} ||= do { - return $self->{relbuilder} ||= DBIx::Class::Schema::Loader::RelBuilder->new ( $self ); + no warnings 'uninitialized'; + my $relbuilder_suff = + {qw{ + v4 ::Compat::v0_040 + v5 ::Compat::v0_05 + v6 ::Compat::v0_06 + }} + ->{ $self->naming->{relationships}}; + + my $relbuilder_class = 'DBIx::Class::Schema::Loader::RelBuilder'.$relbuilder_suff; + eval "require $relbuilder_class"; die $@ if $@; + $relbuilder_class->new( $self ); + + }; } sub _load_tables { diff --git a/lib/DBIx/Class/Schema/Loader/RelBuilder.pm b/lib/DBIx/Class/Schema/Loader/RelBuilder.pm index 06edf33..be0f136 100644 --- a/lib/DBIx/Class/Schema/Loader/RelBuilder.pm +++ b/lib/DBIx/Class/Schema/Loader/RelBuilder.pm @@ -4,6 +4,8 @@ use strict; use warnings; use Class::C3; use Carp::Clan qw/^DBIx::Class/; +use Scalar::Util (); + use Lingua::EN::Inflect::Phrase (); use DBIx::Class::Schema::Loader::Utils 'split_name';