tests cleaned a little, added autoloading of on-disk class defs, added currently...
Brandon Black [Fri, 17 Feb 2006 04:40:00 +0000 (04:40 +0000)]
21 files changed:
Build.PL
Changes
MANIFEST
MANIFEST.SKIP
META.yml
README
TODO
lib/DBIx/Class/Schema/Loader.pm
lib/DBIx/Class/Schema/Loader/Generic.pm
t/01use.t
t/10sqlite_common.t
t/11mysql_common.t
t/12pg_common.t
t/13db2_common.t
t/lib/DBIXCSL_Test/Schema/LoaderTest1.pm [new file with mode: 0644]
t/lib/DBIx/Class/TestComponent.pm [new file with mode: 0644]
t/lib/DBIx/Class/TestRSComponent.pm [new file with mode: 0644]
t/lib/TestAdditional.pm [moved from t/TestAdditional.pm with 100% similarity]
t/lib/TestAdditionalBase.pm [moved from t/TestAdditionalBase.pm with 100% similarity]
t/lib/TestLeftBase.pm [moved from t/TestLeftBase.pm with 100% similarity]
t/lib/dbixcsl_common_tests.pm [moved from t/dbixcsl_common_tests.pm with 88% similarity]

index e9c8f22..a35c472 100644 (file)
--- a/Build.PL
+++ b/Build.PL
@@ -5,7 +5,7 @@ my %arguments = (
     license            => 'perl',
     module_name        => 'DBIx::Class::Schema::Loader',
     requires           => {
-        'DBIx::Class'           => 0.05,
+        'DBIx::Class'           => 0.05005,
         'UNIVERSAL::require'    => 0.10,
         'Lingua::EN::Inflect'   => 0,
         'Text::Balanced'        => 0,
diff --git a/Changes b/Changes
index ead1704..495271c 100644 (file)
--- a/Changes
+++ b/Changes
@@ -1,5 +1,13 @@
 Revision history for Perl extension DBIx::Class::Schema::Loader
 
+0.02001 Not Yet Released...
+        - tests fixed up a bit
+       - auto-loading of on-disk class definitions layered on top
+         of the generated definitions (create Foo::Schema::Bar, then
+         also try to ->require it if it exists on disk).
+       - new parameters components and resultset_components, which do
+         the obvious for the generated table classes.
+
 0.02000 Sun Feb 12 22:43:47 UTC 2006
         - Just docs/version update, 0.01004 code released as 0.02000
 
index 509e9cf..763f6f5 100644 (file)
--- a/MANIFEST
+++ b/MANIFEST
@@ -9,6 +9,8 @@ lib/DBIx/Class/Schema/Loader/SQLite.pm
 lib/DBIx/Class/Schema/Loader/Writing.pm
 Makefile.PL
 MANIFEST                       This list of files
+META.yml
+README
 t/01use.t
 t/02pod.t
 t/03podcoverage.t
@@ -16,10 +18,11 @@ t/10sqlite_common.t
 t/11mysql_common.t
 t/12pg_common.t
 t/13db2_common.t
-t/dbixcsl_common_tests.pm
-t/TestAdditional.pm
-t/TestAdditionalBase.pm
-t/TestLeftBase.pm
+t/lib/DBIx/Class/TestComponent.pm
+t/lib/DBIx/Class/TestRSComponent.pm
+t/lib/dbixcsl_common_tests.pm
+t/lib/DBIXCSL_Test/Schema/LoaderTest1.pm
+t/lib/TestAdditional.pm
+t/lib/TestAdditionalBase.pm
+t/lib/TestLeftBase.pm
 TODO
-META.yml
-README
index d25803e..9d68608 100644 (file)
@@ -37,3 +37,6 @@
 
 # Skip maint stuff
 ^maint/
+
+# Skip coverage output
+^cover_db/
index 858167a..0e9003b 100644 (file)
--- a/META.yml
+++ b/META.yml
@@ -1,6 +1,6 @@
 ---
 name: DBIx-Class-Schema-Loader
-version: 0.02000
+version: 0.02001
 author:
   - 'Brandon Black, C<blblack@gmail.com>'
 abstract: Dynamic definition of a DBIx::Class::Schema
@@ -9,7 +9,7 @@ requires:
   Class::Accessor::Fast: 0.22
   Class::C3: 0.09
   Class::Data::Accessor: 0.02
-  DBIx::Class: 0.05
+  DBIx::Class: 0.05005
   Lingua::EN::Inflect: 0
   Text::Balanced: 0
   UNIVERSAL::require: 0.1
@@ -20,7 +20,7 @@ build_requires:
 provides:
   DBIx::Class::Schema::Loader:
     file: lib/DBIx/Class/Schema/Loader.pm
-    version: 0.02000
+    version: 0.02001
   DBIx::Class::Schema::Loader::DB2:
     file: lib/DBIx/Class/Schema/Loader/DB2.pm
   DBIx::Class::Schema::Loader::Generic:
diff --git a/README b/README
index 98a4aed..99ac7dd 100644 (file)
--- a/README
+++ b/README
@@ -13,6 +13,8 @@ SYNOPSIS
         additional_classes      => [qw/DBIx::Class::Foo/],
         additional_base_classes => [qw/My::Stuff/],
         left_base_classes       => [qw/DBIx::Class::Bar/],
+        components              => [qw/ResultSetManager/],
+        resultset_components    => [qw/AlwaysRS/],
         constraint              => '^foo.*',
         relationships           => 1,
         options                 => { AutoCommit => 1 }, 
diff --git a/TODO b/TODO
index 47604db..8db718c 100644 (file)
--- a/TODO
+++ b/TODO
@@ -3,10 +3,12 @@ Reminders to myself or whoever else ever looks in here...
 
 SQLite needs some heavy refactoring, the subroutines are becoming too complex to understand easily.
 
+Relationship-building needs to be refactored into a seperate module to share with SQLT.
+
 Relationship stuff:
    Fix multiple rels between same pair of tables
    If local column is UNIQUE or PK, use has_one() for relation?
    Re-scan relations/tables after initial relation setup to find ->many_to_many() relations to be set up?
    Check NULLability of columns involved in the relationship, which might suggest a more optimal non-default -join-type?
-
+   While scanning for many-to-many, scan for implied rels as well? (if foo->belongs_to('bar') and baz->belongs_to('bar'), does that impliy foo->might_have('baz') and the reverse?)
 ...
index 6c403e2..b43b316 100644 (file)
@@ -10,7 +10,7 @@ use UNIVERSAL::require;
 # Always remember to do all digits for the version even if they're 0
 # i.e. first release of 0.XX *must* be 0.XX000. This avoids fBSD ports
 # brain damage and presumably various other packaging systems too
-our $VERSION = '0.02000';
+our $VERSION = '0.02001';
 
 __PACKAGE__->mk_classaccessor('loader');
 
@@ -30,6 +30,8 @@ DBIx::Class::Schema::Loader - Dynamic definition of a DBIx::Class::Schema
     additional_classes      => [qw/DBIx::Class::Foo/],
     additional_base_classes => [qw/My::Stuff/],
     left_base_classes       => [qw/DBIx::Class::Bar/],
+    components              => [qw/ResultSetManager/],
+    resultset_components    => [qw/AlwaysRS/],
     constraint              => '^foo.*',
     relationships           => 1,
     options                 => { AutoCommit => 1 }, 
index 8e0498b..2fc043f 100644 (file)
@@ -22,6 +22,8 @@ __PACKAGE__->mk_ro_accessors(qw/
                                 additional_classes
                                 additional_base_classes
                                 left_base_classes
+                               components
+                               resultset_components
                                 relationships
                                 inflect
                                 db_schema
@@ -61,6 +63,18 @@ List of additional base classes, that need to be leftmost.
 
 List of additional classes which your table classes will use.
 
+=head2 components
+
+List of additional components to be loaded into your table classes.
+A good example would be C<ResultSetManager>.
+
+=head2 resultset_components
+
+List of additional resultset components to be loaded into your table
+classes.  A good example would be C<AlwaysRS>.  Component
+C<ResultSetManager> will be automatically added to the above
+C<components> list if this option is set.
+
 =head2 constraint
 
 Only load tables matching regex.
@@ -129,7 +143,12 @@ sub new {
     $self->{inflect}    ||= {};
     $self->_ensure_arrayref(qw/additional_classes
                                additional_base_classes
-                               left_base_classes/);
+                               left_base_classes
+                              components
+                              resultset_components/);
+
+    push(@{$self->{components}}, 'ResultSetManager')
+        if @{$self->{resultset_components}};
 
     $self->{monikers} = {};
     $self->{classes} = {};
@@ -224,8 +243,8 @@ sub _make_cond_rel {
     my $rev_cond = { reverse %$cond };
 
     for (keys %$rev_cond) {
-       $rev_cond->{"foreign.$_"} = "self.".$rev_cond->{$_};
-       delete $rev_cond->{$_};
+        $rev_cond->{"foreign.$_"} = "self.".$rev_cond->{$_};
+        delete $rev_cond->{$_};
     }
 
     my $cond_printable = _stringify_hash($cond)
@@ -303,6 +322,9 @@ sub _load_classes {
         $self->_inject($table_class, @{$self->additional_base_classes});
         $self->_use   ($table_class, @{$self->additional_classes});
         $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;
@@ -320,6 +342,15 @@ sub _load_classes {
         warn qq/$table_class->set_primary_key('$primaries')\n/
             if $self->debug && @$pks;
 
+        $table_class->require;
+        if($@ && $@ !~ /^Can't locate /) {
+            croak "Failed to load external class definition"
+                  . "for '$table_class': $@";
+        }
+
+        warn qq/# Loaded external class definition for '$table_class'\n/
+            if $self->debug;
+
         $schema->register_class($table_moniker, $table_class);
         $self->classes->{$lc_tblname} = $table_class;
         $self->monikers->{$lc_tblname} = $table_moniker;
index 7222d5d..a998b0c 100644 (file)
--- a/t/01use.t
+++ b/t/01use.t
@@ -1,12 +1,10 @@
 use strict;
-use Test::More tests => 3;
+use Test::More tests => 5;
 
 BEGIN {
-    use_ok 'DBIx::Class::Loader';
-  SKIP: {
-        use_ok 'DBIx::Class::Loader::mysql';
-    }
-  SKIP: {
-        use_ok 'DBIx::Class::Loader::Pg';
-    }
+    use_ok 'DBIx::Class::Schema::Loader';
+    use_ok 'DBIx::Class::Schema::Loader::SQLite';
+    use_ok 'DBIx::Class::Schema::Loader::mysql';
+    use_ok 'DBIx::Class::Schema::Loader::Pg';
+    use_ok 'DBIx::Class::Schema::Loader::DB2';
 }
index 1bbaf05..7899cf6 100644 (file)
@@ -1,5 +1,5 @@
 use strict;
-use lib qw( ./t );
+use lib qw(t/lib);
 use dbixcsl_common_tests;
 
 eval { require DBD::SQLite };
index dac7a51..c65c7b1 100644 (file)
@@ -1,5 +1,5 @@
 use strict;
-use lib qw( . ./t );
+use lib qw(t/lib);
 use dbixcsl_common_tests;
 
 my $dsn         = $ENV{DBICTEST_MYSQL_DSN} || '';
index 92ba833..21e83ec 100644 (file)
@@ -1,5 +1,5 @@
 use strict;
-use lib qw( . ./t );
+use lib qw(t/lib);
 use dbixcsl_common_tests;
 
 my $dsn      = $ENV{DBICTEST_PG_DSN} || '';
index 1619968..b3ce5c9 100644 (file)
@@ -1,5 +1,5 @@
 use strict;
-use lib qw( . ./t );
+use lib qw(t/lib);
 use dbixcsl_common_tests;
 
 my $dsn      = $ENV{DBICTEST_DB2_DSN} || '';
diff --git a/t/lib/DBIXCSL_Test/Schema/LoaderTest1.pm b/t/lib/DBIXCSL_Test/Schema/LoaderTest1.pm
new file mode 100644 (file)
index 0000000..b4c3c65
--- /dev/null
@@ -0,0 +1,7 @@
+package DBIXCSL_Test::Schema::LoaderTest1;
+
+sub loader_test1_classmeth { 'all is well' }
+
+sub loader_test1_rsmeth : ResultSet { 'all is still well' }
+
+1;
diff --git a/t/lib/DBIx/Class/TestComponent.pm b/t/lib/DBIx/Class/TestComponent.pm
new file mode 100644 (file)
index 0000000..48677c7
--- /dev/null
@@ -0,0 +1,5 @@
+package DBIx::Class::TestComponent;
+
+sub dbix_class_testcomponent { 'dbix_class_testcomponent works' }
+
+1;
diff --git a/t/lib/DBIx/Class/TestRSComponent.pm b/t/lib/DBIx/Class/TestRSComponent.pm
new file mode 100644 (file)
index 0000000..73cbed2
--- /dev/null
@@ -0,0 +1,6 @@
+package DBIx::Class::TestRSComponent;
+
+# XXX why is this breaking?
+#sub dbix_class_testrscomponent : ResultSet { 'dbix_class_testrscomponent works' }
+
+1;
similarity index 100%
rename from t/TestAdditional.pm
rename to t/lib/TestAdditional.pm
similarity index 100%
rename from t/TestLeftBase.pm
rename to t/lib/TestLeftBase.pm
similarity index 88%
rename from t/dbixcsl_common_tests.pm
rename to t/lib/dbixcsl_common_tests.pm
index 7497f1f..32c9076 100644 (file)
@@ -37,11 +37,11 @@ sub skip_tests {
 sub run_tests {
     my $self = shift;
 
-    plan tests => 42;
+    plan tests => 50;
 
     $self->create();
 
-    my $schema_class = 'DBIXCSL_Test_' . $self->{vendor} . '::Schema';
+    my $schema_class = 'DBIXCSL_Test::Schema';
 
     my $debug = ($self->{verbose} > 1) ? 1 : 0;
 
@@ -54,6 +54,8 @@ sub run_tests {
         additional_classes      => 'TestAdditional',
         additional_base_classes => 'TestAdditionalBase',
         left_base_classes       => [ qw/TestLeftBase/ ],
+       components              => [ qw/TestComponent/ ],
+       resultset_components    => [ qw/TestRSComponent/ ],
         debug                   => $debug,
     );
 
@@ -83,18 +85,60 @@ sub run_tests {
     isa_ok( $rsobj1, "DBIx::Class::ResultSet" );
     isa_ok( $rsobj2, "DBIx::Class::ResultSet" );
 
-    can_ok( $class1, 'test_additional_base' );
-    can_ok( $class1, 'test_additional_base_override' );
-    can_ok( $class1, 'test_additional_base_additional' );
+    {
+        my ($skip_tab, $skip_tabo, $skip_taba, $skip_cmeth,
+           $skip_rsmeth, $skip_tcomp, $skip_trscomp);
 
-    is( $class1->test_additional_base, "test_additional_base",
-        "Additional Base method" );
+        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, 'loader_test1_classmeth' ) or $skip_cmeth = 1;
+        can_ok( $rsobj1, 'loader_test1_rsmeth' ) or $skip_rsmeth = 1;
 
-    is( $class1->test_additional_base_override, "test_left_base_override",
-        "Left Base overrides Additional Base method" );
+        SKIP: {
+           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;
+            is( $class1->test_additional_base_override,
+               "test_left_base_override",
+                "Left Base overrides Additional Base method" );
+        }
+
+        SKIP: {
+           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;
+            is( $class1->dbix_class_testcomponent,
+               'dbix_class_testcomponent works' );
+       }
+
+       SKIP: {
+           skip "Pre-requisite test failed", 1 if $skip_trscomp;
+            is( $rsobj1->dbix_class_testrscomponent,
+               'dbix_class_testrscomponent works' );
+       }
+
+       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;
+            is( $rsobj1->loader_test1_rsmeth, 'all is still well' );
+       }
+    }
 
-    is( $class1->test_additional_base_additional, "test_additional",
-        "Additional Base can use Additional package method" );
 
     my $obj    = $rsobj1->find(1);
     is( $obj->id,  1 );