From: Dagfinn Ilmari Mannsåker Date: Sun, 19 Apr 2009 08:59:08 +0000 (+0000) Subject: Replace UNIVERSAL::require with Class::C3::Componentised X-Git-Tag: 0.04999_08~24 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=6ae3f335e1b67e8fdcb7b9a52cca64fd8c01af29;p=dbsrgits%2FDBIx-Class-Schema-Loader.git Replace UNIVERSAL::require with Class::C3::Componentised --- diff --git a/Changes b/Changes index 8d42b59..3a6517c 100644 --- a/Changes +++ b/Changes @@ -1,5 +1,8 @@ Revision history for Perl extension DBIx::Class::Schema::Loader +0.04999_08 Not Yet Released + - Replace UNIVERSAL::require with Class::C3::Componentised + 0.04999_07 2009-04-18 - Add result_base_class and schema_base_class options (RT #43977) - Ignore duplicate uniq indices (including duplicates of the PK). diff --git a/Makefile.PL b/Makefile.PL index 9a27387..a81c59e 100644 --- a/Makefile.PL +++ b/Makefile.PL @@ -13,13 +13,13 @@ test_requires 'IPC::Open3' => 0; requires 'File::Spec' => 0; requires 'Scalar::Util' => 0; requires 'Data::Dump' => '1.06'; -requires 'UNIVERSAL::require' => '0.11'; requires 'Lingua::EN::Inflect::Number' => '1.1'; requires 'Text::Balanced' => 0; requires 'Digest::MD5' => '2.36'; requires 'Class::Accessor::Fast' => '0.30'; requires 'Class::Data::Accessor' => '0.03'; requires 'Class::C3' => '0.18'; +requires 'Class::C3::Componentised' => 0; requires 'Carp::Clan' => 0; requires 'Class::Inspector' => 0; requires 'DBIx::Class' => '0.07006'; diff --git a/lib/DBIx/Class/Schema/Loader.pm b/lib/DBIx/Class/Schema/Loader.pm index 35bd0ad..edc3df3 100644 --- a/lib/DBIx/Class/Schema/Loader.pm +++ b/lib/DBIx/Class/Schema/Loader.pm @@ -4,7 +4,6 @@ use strict; use warnings; use base qw/DBIx::Class::Schema Class::Data::Accessor/; use Carp::Clan qw/^DBIx::Class/; -use UNIVERSAL::require; use Class::C3; use Scalar::Util qw/ weaken /; @@ -131,9 +130,8 @@ sub _invoke_loader { my $impl = $self->loader_class || "DBIx::Class::Schema::Loader" . $self->storage_type; $impl = "DBIx::Class::Schema::Loader${impl}" if $impl =~ /^::/; - $impl->require or - croak qq/Could not load storage_type loader "$impl": / . - qq/"$UNIVERSAL::require::ERROR"/; + eval { $self->ensure_class_loaded($impl) }; + croak qq/Could not load storage_type loader "$impl": "$@"/ if $@; $self->_loader($impl->new(%$args)); $self->_loader->load; diff --git a/lib/DBIx/Class/Schema/Loader/Base.pm b/lib/DBIx/Class/Schema/Loader/Base.pm index e0c84b1..9bc5673 100644 --- a/lib/DBIx/Class/Schema/Loader/Base.pm +++ b/lib/DBIx/Class/Schema/Loader/Base.pm @@ -2,7 +2,7 @@ package DBIx::Class::Schema::Loader::Base; use strict; use warnings; -use base qw/Class::Accessor::Fast/; +use base qw/Class::Accessor::Fast Class::C3::Componentised/; use Class::C3; use Carp::Clan qw/^DBIx::Class/; use DBIx::Class::Schema::Loader::RelBuilder; @@ -443,9 +443,9 @@ sub _reload_classes { ) { my $has_file = Class::Inspector->loaded_filename($resultset_class); Class::Unload->unload($resultset_class); - $self->schema->ensure_class_loaded($resultset_class) if $has_file; + $self->ensure_class_loaded($resultset_class) if $has_file; } - $self->schema->ensure_class_loaded($class); + $self->ensure_class_loaded($class); } push @to_register, [$moniker, $class]; } diff --git a/lib/DBIx/Class/Schema/Loader/DBI.pm b/lib/DBIx/Class/Schema/Loader/DBI.pm index 14474a8..a7d6ddf 100644 --- a/lib/DBIx/Class/Schema/Loader/DBI.pm +++ b/lib/DBIx/Class/Schema/Loader/DBI.pm @@ -5,7 +5,6 @@ use warnings; use base qw/DBIx::Class::Schema::Loader::Base/; use Class::C3; use Carp::Clan qw/^DBIx::Class/; -use UNIVERSAL::require; our $VERSION = '0.04999_07'; @@ -39,13 +38,13 @@ sub new { # rebless to vendor-specific class if it exists and loads my $dbh = $self->schema->storage->dbh; my $driver = $dbh->{Driver}->{Name}; + my $subclass = 'DBIx::Class::Schema::Loader::DBI::' . $driver; - $subclass->require; - if($@ && $@ !~ /^Can't locate /) { - croak "Failed to require $subclass: $@"; - } - elsif(!$@) { + if ($self->ensure_class_found($subclass)) { + eval { $self->ensure_class_loaded($subclass) }; + croak "Failed to load $subclass: $@" if $@; bless $self, $subclass unless $self->isa($subclass); + $self->_rebless(); } # Set up the default quoting character and name seperators @@ -71,6 +70,9 @@ sub new { # Override this in vendor modules to do things at the end of ->new() sub _setup { } +# Override this in vendor module to load a subclass if necessary +sub _rebless { } + # Returns an array of table names sub _tables_list { my $self = shift;