From: Brandon Black Date: Fri, 17 Feb 2006 12:35:35 +0000 (+0000) Subject: more work on components, base classes, and resultset_components - still broken in... X-Git-Tag: 0.03000~19 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=9fa996830cb2c629201a73f80e265f8f65c8c62e;p=dbsrgits%2FDBIx-Class-Schema-Loader.git more work on components, base classes, and resultset_components - still broken in one test case (and some whitespace fixes) --- diff --git a/lib/DBIx/Class/Schema/Loader/DB2.pm b/lib/DBIx/Class/Schema/Loader/DB2.pm index 4555dc2..9bfa285 100644 --- a/lib/DBIx/Class/Schema/Loader/DB2.pm +++ b/lib/DBIx/Class/Schema/Loader/DB2.pm @@ -31,7 +31,7 @@ See L. =cut sub _db_classes { - return qw/DBIx::Class::PK::Auto::DB2/; + return qw/PK::Auto::DB2/; } sub _tables { diff --git a/lib/DBIx/Class/Schema/Loader/Generic.pm b/lib/DBIx/Class/Schema/Loader/Generic.pm index 2fc043f..d226d6b 100644 --- a/lib/DBIx/Class/Schema/Loader/Generic.pm +++ b/lib/DBIx/Class/Schema/Loader/Generic.pm @@ -22,8 +22,8 @@ __PACKAGE__->mk_ro_accessors(qw/ additional_classes additional_base_classes left_base_classes - components - resultset_components + components + resultset_components relationships inflect db_schema @@ -144,8 +144,8 @@ sub new { $self->_ensure_arrayref(qw/additional_classes additional_base_classes left_base_classes - components - resultset_components/); + components + resultset_components/); push(@{$self->{components}}, 'ResultSetManager') if @{$self->{resultset_components}}; @@ -317,14 +317,15 @@ sub _load_classes { my $table_moniker = $self->_table2moniker($db_schema, $tbl); my $table_class = $schema . q{::} . $table_moniker; - $self->_inject($table_class, 'DBIx::Class::Core'); - $self->_inject($table_class, @db_classes); - $self->_inject($table_class, @{$self->additional_base_classes}); + { no strict 'refs'; + @{"${table_class}::ISA"} = ($schema); + } $self->_use ($table_class, @{$self->additional_classes}); + $self->_inject($table_class, @{$self->additional_base_classes}); + $table_class->load_components(@{$self->components}, @db_classes, 'Core'); + $table_class->load_resultset_components(@{$self->resultset_components}) + if @{$self->resultset_components}; $self->_inject($table_class, @{$self->left_base_classes}); - $table_class->load_components(@{$self->components}); - $table_class->load_resultset_components(@{$self->resultset_components}) - if @{$self->resultset_components}; warn qq/\# Initializing table "$tablename" as "$table_class"\n/ if $self->debug; diff --git a/lib/DBIx/Class/Schema/Loader/Pg.pm b/lib/DBIx/Class/Schema/Loader/Pg.pm index 640b43a..af579e7 100644 --- a/lib/DBIx/Class/Schema/Loader/Pg.pm +++ b/lib/DBIx/Class/Schema/Loader/Pg.pm @@ -45,7 +45,7 @@ sub new { } sub _db_classes { - return qw/DBIx::Class::PK::Auto::Pg/; + return qw/PK::Auto::Pg/; } sub _tables { diff --git a/lib/DBIx/Class/Schema/Loader/SQLite.pm b/lib/DBIx/Class/Schema/Loader/SQLite.pm index 1469923..f4065a1 100644 --- a/lib/DBIx/Class/Schema/Loader/SQLite.pm +++ b/lib/DBIx/Class/Schema/Loader/SQLite.pm @@ -28,7 +28,7 @@ See L. =cut sub _db_classes { - return qw/DBIx::Class::PK::Auto::SQLite/; + return qw/PK::Auto::SQLite/; } # XXX this really needs a re-factor @@ -79,7 +79,7 @@ SELECT sql FROM sqlite_master WHERE tbl_name = ? # Grab reference chomp $col; - next if $col !~ /^(.*)\s+REFERENCES\s+(\w+) (?: \s* \( (.*) \) )? /ix; + next if $col !~ /^(.*)\s+REFERENCES\s+(\w+) (?: \s* \( (.*) \) )? /ix; my ($cols, $f_table, $f_cols) = ($1, $2, $3); diff --git a/lib/DBIx/Class/Schema/Loader/Writing.pm b/lib/DBIx/Class/Schema/Loader/Writing.pm index d0117a5..0036db4 100644 --- a/lib/DBIx/Class/Schema/Loader/Writing.pm +++ b/lib/DBIx/Class/Schema/Loader/Writing.pm @@ -20,7 +20,7 @@ DBIx::Class::Schema::Loader::Writing - Loader subclass writing guide use Class::C3; sub _db_classes { - return qw/DBIx::Class::PK::Auto::Foo/; + return qw/PK::Auto::Foo/; # You may want to return more, or less, than this. } diff --git a/lib/DBIx/Class/Schema/Loader/mysql.pm b/lib/DBIx/Class/Schema/Loader/mysql.pm index 97fceaa..7a7d322 100644 --- a/lib/DBIx/Class/Schema/Loader/mysql.pm +++ b/lib/DBIx/Class/Schema/Loader/mysql.pm @@ -29,7 +29,7 @@ See L. =cut sub _db_classes { - return qw/DBIx::Class::PK::Auto::MySQL/; + return qw/PK::Auto::MySQL/; } sub _load_relationships { diff --git a/t/lib/DBIx/Class/TestRSComponent.pm b/t/lib/DBIx/Class/TestRSComponent.pm index 73cbed2..6744a64 100644 --- a/t/lib/DBIx/Class/TestRSComponent.pm +++ b/t/lib/DBIx/Class/TestRSComponent.pm @@ -1,6 +1,6 @@ package DBIx::Class::TestRSComponent; +use base qw/DBIx::Class::ResultSet/; -# XXX why is this breaking? -#sub dbix_class_testrscomponent : ResultSet { 'dbix_class_testrscomponent works' } +sub dbix_class_testrscomponent : ResultSet { 'dbix_class_testrscomponent works' } 1; diff --git a/t/lib/dbixcsl_common_tests.pm b/t/lib/dbixcsl_common_tests.pm index 32c9076..b89ba30 100644 --- a/t/lib/dbixcsl_common_tests.pm +++ b/t/lib/dbixcsl_common_tests.pm @@ -54,8 +54,8 @@ sub run_tests { additional_classes => 'TestAdditional', additional_base_classes => 'TestAdditionalBase', left_base_classes => [ qw/TestLeftBase/ ], - components => [ qw/TestComponent/ ], - resultset_components => [ qw/TestRSComponent/ ], + components => [ qw/TestComponent/ ], + resultset_components => [ qw/TestRSComponent/ ], debug => $debug, ); @@ -87,56 +87,56 @@ sub run_tests { { my ($skip_tab, $skip_tabo, $skip_taba, $skip_cmeth, - $skip_rsmeth, $skip_tcomp, $skip_trscomp); + $skip_rsmeth, $skip_tcomp, $skip_trscomp); can_ok( $class1, 'test_additional_base' ) or $skip_tab = 1; can_ok( $class1, 'test_additional_base_override' ) or $skip_tabo = 1; can_ok( $class1, 'test_additional_base_additional' ) or $skip_taba = 1; - can_ok( $class1, 'dbix_class_testcomponent' ) or $skip_tcomp = 1; - can_ok( $class1, 'dbix_class_testrscomponent' ) or $skip_trscomp = 1; + can_ok( $class1, 'dbix_class_testcomponent' ) or $skip_tcomp = 1; + can_ok( $rsobj1, 'dbix_class_testrscomponent' ) or $skip_trscomp = 1; can_ok( $class1, 'loader_test1_classmeth' ) or $skip_cmeth = 1; can_ok( $rsobj1, 'loader_test1_rsmeth' ) or $skip_rsmeth = 1; SKIP: { - skip "Pre-requisite test failed", 1 if $skip_tab; + skip "Pre-requisite test failed", 1 if $skip_tab; is( $class1->test_additional_base, "test_additional_base", "Additional Base method" ); - } + } SKIP: { - skip "Pre-requisite test failed", 1 if $skip_tabo; + skip "Pre-requisite test failed", 1 if $skip_tabo; is( $class1->test_additional_base_override, - "test_left_base_override", + "test_left_base_override", "Left Base overrides Additional Base method" ); } SKIP: { - skip "Pre-requisite test failed", 1 if $skip_taba; + skip "Pre-requisite test failed", 1 if $skip_taba; is( $class1->test_additional_base_additional, "test_additional", "Additional Base can use Additional package method" ); } - SKIP: { - skip "Pre-requisite test failed", 1 if $skip_tcomp; + SKIP: { + skip "Pre-requisite test failed", 1 if $skip_tcomp; is( $class1->dbix_class_testcomponent, - 'dbix_class_testcomponent works' ); - } + 'dbix_class_testcomponent works' ); + } - SKIP: { - skip "Pre-requisite test failed", 1 if $skip_trscomp; + SKIP: { + skip "Pre-requisite test failed", 1 if $skip_trscomp; is( $rsobj1->dbix_class_testrscomponent, - 'dbix_class_testrscomponent works' ); - } + 'dbix_class_testrscomponent works' ); + } - SKIP: { - skip "Pre-requisite test failed", 1 if $skip_cmeth; + SKIP: { + skip "Pre-requisite test failed", 1 if $skip_cmeth; is( $class1->loader_test1_classmeth, 'all is well' ); - } + } - SKIP: { - skip "Pre-requisite test failed", 1 if $skip_rsmeth; + SKIP: { + skip "Pre-requisite test failed", 1 if $skip_rsmeth; is( $rsobj1->loader_test1_rsmeth, 'all is still well' ); - } + } } @@ -191,9 +191,9 @@ sub run_tests { my $obj4 = $rsobj4->find(123); isa_ok( $obj4->fkid, $class3); - my $obj3 = $rsobj3->find(1); - my $rs_rel4 = $obj3->search_related('loader_test4s'); - isa_ok( $rs_rel4->first, $class4); + my $obj3 = $rsobj3->find(1); + my $rs_rel4 = $obj3->search_related('loader_test4s'); + isa_ok( $rs_rel4->first, $class4); # fk def in comments should not be parsed my $obj5 = $rsobj5->find( id1 => 1, id2 => 1 );