add schema_components option
Rafael Kitover [Tue, 5 Jul 2011 09:30:55 +0000 (05:30 -0400)]
Changes
TODO
lib/DBIx/Class/Schema/Loader/Base.pm
t/lib/DBIx/Class/TestSchemaComponent.pm [new file with mode: 0644]
t/lib/TestSchemaComponentFQN.pm [new file with mode: 0644]
t/lib/dbixcsl_common_tests.pm

diff --git a/Changes b/Changes
index bc34c3d..138dd1a 100644 (file)
--- a/Changes
+++ b/Changes
@@ -1,5 +1,6 @@
 Revision history for Perl extension DBIx::Class::Schema::Loader
 
+        - add schema_components option
         - sort relationships so they always come out in the same order
         - add rel_name_map option
         - fix the decimal data type for MS Access over ODBC
diff --git a/TODO b/TODO
index 39b8bb4..dd1f19b 100644 (file)
--- a/TODO
+++ b/TODO
@@ -43,6 +43,7 @@
     - generate Schema/ResultBase.pm and Schema/ResultSetBase.pm
     - remove additional warnings skip in t/22dump.t for ActivePerl on Win32
     - make 23dumpmore.t auto cleanup and remove dump warnings
+    - generate POD for schema class with class list
 
 - Relationships
    - Re-scan relations/tables after initial relation setup to find
index eba2832..16cde2b 100644 (file)
@@ -38,6 +38,7 @@ __PACKAGE__->mk_group_ro_accessors('simple', qw/
                                 additional_base_classes
                                 left_base_classes
                                 components
+                                schema_components
                                 skip_relationships
                                 skip_load_external
                                 moniker_map
@@ -423,9 +424,13 @@ that need to be leftmost.
 
 List of additional classes which all of your table classes will use.
 
+=head2 schema_components
+
+List of components to load into the Schema class.
+
 =head2 components
 
-List of additional components to be loaded into all of your table
+List of additional components to be loaded into all of your Result
 classes.  A good example would be
 L<InflateColumn::DateTime|DBIx::Class::InflateColumn::DateTime>
 
@@ -643,8 +648,9 @@ L<DBIx::Class::Schema::Loader>.
 my $CURRENT_V = 'v7';
 
 my @CLASS_ARGS = qw(
-    schema_base_class result_base_class additional_base_classes
-    left_base_classes additional_classes components result_roles
+    schema_components schema_base_class result_base_class
+    additional_base_classes left_base_classes additional_classes components
+    result_roles
 );
 
 # ensure that a peice of object data is a valid arrayref, creating
@@ -712,7 +718,8 @@ sub new {
         if ((not defined $self->use_moose) || (not $self->use_moose))
             && ((defined $self->result_roles) || (defined $self->result_roles_map));
 
-    $self->_ensure_arrayref(qw/additional_classes
+    $self->_ensure_arrayref(qw/schema_components
+                               additional_classes
                                additional_base_classes
                                left_base_classes
                                components
@@ -1447,6 +1454,15 @@ sub _dump_to_dir {
         $schema_text .= qq|use strict;\nuse warnings;\n\nuse base '$schema_base_class';\n\n|;
     }
 
+    my @schema_components = @{ $self->schema_components || [] };
+
+    if (@schema_components) {
+        my $schema_components = dump @schema_components;
+        $schema_components = "($schema_components)" if @schema_components == 1;
+
+        $schema_text .= "__PACKAGE__->load_components${schema_components};\n\n";
+    }
+
     if ($self->use_namespaces) {
         $schema_text .= qq|__PACKAGE__->load_namespaces|;
         my $namespace_options;
diff --git a/t/lib/DBIx/Class/TestSchemaComponent.pm b/t/lib/DBIx/Class/TestSchemaComponent.pm
new file mode 100644 (file)
index 0000000..21cd853
--- /dev/null
@@ -0,0 +1,5 @@
+package DBIx::Class::TestSchemaComponent;
+
+sub dbix_class_testschemacomponent { 'dbix_class_testschemacomponent works' }
+
+1;
diff --git a/t/lib/TestSchemaComponentFQN.pm b/t/lib/TestSchemaComponentFQN.pm
new file mode 100644 (file)
index 0000000..1b4c6c2
--- /dev/null
@@ -0,0 +1,5 @@
+package TestSchemaComponentFQN;
+
+sub testschemacomponent_fqn { 'TestSchemaComponentFQN works' }
+
+1;
index 0739692..7fa48b4 100644 (file)
@@ -120,7 +120,7 @@ sub run_tests {
     $num_rescans++ if $self->{vendor} eq 'Firebird';
 
     plan tests => @connect_info *
-        (209 + $num_rescans * $col_accessor_map_tests + $extra_count + ($self->{data_type_tests}{test_count} || 0));
+        (210 + $num_rescans * $col_accessor_map_tests + $extra_count + ($self->{data_type_tests}{test_count} || 0));
 
     foreach my $info_idx (0..$#connect_info) {
         my $info = $connect_info[$info_idx];
@@ -230,6 +230,7 @@ sub setup_schema {
           qr/^(?:\S+\.)?(?:(?:$self->{vendor}|extra)[_-]?)?loader[_-]?test[0-9]+(?!.*_)/i,
         result_namespace        => RESULT_NAMESPACE,
         resultset_namespace     => RESULTSET_NAMESPACE,
+        schema_components       => [ 'TestSchemaComponent', '+TestSchemaComponentFQN' ],
         additional_classes      => 'TestAdditional',
         additional_base_classes => 'TestAdditionalBase',
         left_base_classes       => [ qw/TestLeftBase/ ],
@@ -391,6 +392,10 @@ sub test_schema {
     is_deeply $schema_resultset_namespace, RESULTSET_NAMESPACE,
         'resultset_namespace set correctly on Schema';
 
+    like $schema_code,
+qr/\n__PACKAGE__->load_components\("TestSchemaComponent", "\+TestSchemaComponentFQN"\);\n\n__PACKAGE__->load_namespaces/,
+        'schema_components works';
+
     my @columns_lt2 = $class2->columns;
     is_deeply( \@columns_lt2, [ qw/id dat dat2 set_primary_key can dbix_class_testcomponent dbix_class_testcomponentmap testcomponent_fqn meta test_role_method test_role_for_map_method crumb_crisp_coating/ ], "Column Ordering" );