requires 'Digest::MD5' => '2.36';
requires 'Class::Accessor::Grouped' => '0.10002';
requires 'MRO::Compat' => '0.09';
+requires 'Sub::Name' => 0;
requires 'Class::C3::Componentised' => '1.0008';
requires 'Carp::Clan' => 0;
requires 'Class::Inspector' => 0;
use strict;
use warnings;
use base qw/DBIx::Class::Schema Class::Accessor::Grouped/;
+use MRO::Compat;
use mro 'c3';
use Carp::Clan qw/^DBIx::Class/;
use Scalar::Util 'weaken';
+use Sub::Name 'subname';
use namespace::clean;
# Always remember to do all digits for the version even if they're 0
my $self = shift;
if($_[-1] && ref $_[-1] eq 'HASH') {
- for my $option (qw/ loader_class loader_options result_base_class schema_base_class/) {
+ for my $option (qw/loader_class loader_options/) {
if(my $value = delete $_[-1]->{$option}) {
$self->$option($value);
}
pop @_ if !keys %{$_[-1]};
}
- $self = $self->next::method(@_);
+ # Make sure we inherit from schema_base_class and load schema_components
+ # before connecting.
+ require DBIx::Class::Schema::Loader::Base;
+ my $temp_loader = DBIx::Class::Schema::Loader::Base->new(
+ %{ $self->_loader_args }
+ );
+
+ if ($temp_loader->schema_base_class || $temp_loader->schema_components) {
+ my @components = @{ $temp_loader->schema_components }
+ if $temp_loader->schema_components;
+
+ push @components, ('+'.$temp_loader->schema_base_class)
+ if $temp_loader->schema_base_class;
+
+ $self->load_components(@components);
+ }
+
+ # This hack is necessary if we changed @ISA of $self through ->load_components.
+ {
+ no warnings 'redefine';
+
+ local *connection = subname __PACKAGE__.'::connection' => sub {
+ my $self = shift;
+ $self->next::method(@_);
+ };
+
+ $self = $self->connection(@_);
+ }
my $class = ref $self || $self;
if(!$class->_loader_invoked) {
+++ /dev/null
-# test that the class in schema_base_class gets used when loading the schema
-# by Ben Tilly ( btilly -at| gmail.com )
-
-use strict;
-use Test::More tests => 1;
-use DBIx::Class::Schema::Loader qw(make_schema_at);
-use lib 't/lib';
-use make_dbictest_db;
-
-make_schema_at(
- 'DBICTest::Schema::_test_schema_base',
- {
- really_erase_my_files => 1,
- naming => 'current',
- use_namespaces => 0,
- schema_base_class => 'TestSchemaBaseClass',
- },
- [ $make_dbictest_db::dsn ],
-);
-
-ok($TestSchemaBaseClass::test_ok, "Connected using schema_base_class.");
--- /dev/null
+use strict;
+use warnings;
+no warnings 'once';
+use Test::More tests => 2;
+use DBIx::Class::Schema::Loader 'make_schema_at';
+use lib 't/lib';
+use make_dbictest_db;
+
+make_schema_at(
+ 'DBICTest::Schema::_test_schema_base',
+ {
+ naming => 'current',
+ schema_base_class => 'TestSchemaBaseClass',
+ schema_components => ['TestSchemaComponent'],
+ },
+ [ $make_dbictest_db::dsn ],
+);
+
+ok $TestSchemaBaseClass::test_ok,
+ 'connected using schema_base_class';
+
+ok $DBIx::Class::TestSchemaComponent::test_component_ok,
+ 'connected using schema_components';
package DBIx::Class::TestSchemaComponent;
+use strict;
+use warnings;
+
+our $test_component_ok = 0;
+
+sub connection {
+ my ($self, @info) = @_;
+
+ $test_component_ok = 1;
+
+ return $self->next::method(@info);
+}
+
sub dbix_class_testschemacomponent { 'dbix_class_testschemacomponent works' }
1;