From: Rafael Kitover <rkitover@cpan.org>
Date: Tue, 17 May 2011 18:59:41 +0000 (-0400)
Subject: move roles to the end of the generated class so that "requires" works with columns... 
X-Git-Tag: 0.07011~114
X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=4f807130f4c199e504ab638259bdb6c9b13ff566;p=dbsrgits%2FDBIx-Class-Schema-Loader.git

move roles to the end of the generated class so that "requires" works with columns/rels
---

diff --git a/lib/DBIx/Class/Schema/Loader/Base.pm b/lib/DBIx/Class/Schema/Loader/Base.pm
index 4430ae0..f425f4a 100644
--- a/lib/DBIx/Class/Schema/Loader/Base.pm
+++ b/lib/DBIx/Class/Schema/Loader/Base.pm
@@ -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
diff --git a/t/lib/TestRoleForMap.pm b/t/lib/TestRoleForMap.pm
index 6160bfb..6e996a8 100644
--- a/t/lib/TestRoleForMap.pm
+++ b/t/lib/TestRoleForMap.pm
@@ -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;