move roles to the end of the generated class so that "requires" works with columns...
Rafael Kitover [Tue, 17 May 2011 18:59:41 +0000 (14:59 -0400)]
lib/DBIx/Class/Schema/Loader/Base.pm
t/lib/TestRoleForMap.pm

index 4430ae0..f425f4a 100644 (file)
@@ -1187,6 +1187,8 @@ sub _load_tables {
         @INC = grep $_ ne $self->dump_directory, @INC;
     }
 
+    $self->_load_roles($_) for @tables;
+
     $self->_load_external($_)
         for map { $self->classes->{$_} } @tables;
 
@@ -1694,12 +1696,6 @@ sub _make_src_class {
     $self->_dbic_stmt($table_class, 'load_components', @components) if @components;
 
     $self->_inject($table_class, @{$self->additional_base_classes});
-
-    my @roles = @{ $self->result_roles || [] };
-    push @roles, @{ $self->result_roles_map->{$table_moniker} }
-        if exists $self->result_roles_map->{$table_moniker};
-
-    $self->_with($table_class, @roles) if @roles;
 }
 
 sub _is_result_class_method {
@@ -1833,7 +1829,7 @@ sub _setup_src_meta {
     my $schema       = $self->schema;
     my $schema_class = $self->schema_class;
 
-    my $table_class = $self->classes->{$table};
+    my $table_class   = $self->classes->{$table};
     my $table_moniker = $self->monikers->{$table};
 
     my $table_name = $table;
@@ -1998,6 +1994,19 @@ sub _load_relationships {
     }
 }
 
+sub _load_roles {
+    my ($self, $table) = @_;
+
+    my $table_moniker = $self->monikers->{$table};
+    my $table_class   = $self->classes->{$table};
+
+    my @roles = @{ $self->result_roles || [] };
+    push @roles, @{ $self->result_roles_map->{$table_moniker} }
+        if exists $self->result_roles_map->{$table_moniker};
+
+    $self->_with($table_class, @roles) if @roles;
+}
+
 # Overload these in driver class:
 
 # Returns an arrayref of column names
index 6160bfb..6e996a8 100644 (file)
@@ -2,6 +2,8 @@ package TestRoleForMap;
 
 use Moose::Role;
 
+requires qw/id dat meta/; # in loader_test2
+
 sub test_role_for_map_method { 'test_role_for_map_method works' }
 
 1;