Initial, ghetto, but working version of resultset components
Arthur Axel 'fREW' Schmidt [Sat, 17 Jul 2010 18:05:51 +0000 (13:05 -0500)]
lib/DBIx/Class/ResultSource.pm
lib/DBIx/Class/ResultSourceProxy.pm
t/lib/A/Useless.pm [new file with mode: 0644]
t/lib/DBICTest/Schema/Artist.pm
t/resultset/components.t [new file with mode: 0644]

index 46ad67a..e8920b0 100644 (file)
@@ -1884,4 +1884,16 @@ You may distribute this code under the same terms as Perl itself.
 
 =cut
 
+sub inject_resultset_components {
+   my $self       = shift;
+   my @components = @{shift @_};
+
+   # this generation of class bit needs to go into CCC
+   my $class = $self->resultset_class . '::' . rand(100);
+   Class::C3::Componentised->inject_base($class, $self->resultset_class);
+   $self->resultset_class($class);
+
+   $self->resultset_class->load_components(@components);
+}
+
 1;
index 1f74eea..8489c8a 100644 (file)
@@ -80,6 +80,8 @@ for my $method_to_proxy (qw/
   relationships
   relationship_info
   has_relationship
+
+  inject_resultset_components
 /) {
   no strict qw/refs/;
   *{__PACKAGE__."::$method_to_proxy"} = subname $method_to_proxy => sub {
diff --git a/t/lib/A/Useless.pm b/t/lib/A/Useless.pm
new file mode 100644 (file)
index 0000000..d1a038d
--- /dev/null
@@ -0,0 +1,3 @@
+package A::Useless;
+
+1;
index b089287..530ee89 100644 (file)
@@ -1,4 +1,4 @@
-package # hide from PAUSE 
+package # hide from PAUSE
     DBICTest::Schema::Artist;
 
 use base qw/DBICTest::BaseResult/;
@@ -65,6 +65,7 @@ __PACKAGE__->has_many(
 );
 __PACKAGE__->many_to_many('artworks', 'artwork_to_artist', 'artwork');
 
+__PACKAGE__->result_source_instance->inject_resultset_components(['+A::Useless']);
 
 sub sqlt_deploy_hook {
   my ($self, $sqlt_table) = @_;
diff --git a/t/resultset/components.t b/t/resultset/components.t
new file mode 100644 (file)
index 0000000..c4b54b6
--- /dev/null
@@ -0,0 +1,14 @@
+use strict;
+use warnings;
+
+use Test::More;
+
+use lib qw(t/lib);
+use DBICTest;
+
+my $schema = DBICTest->init_schema;
+
+isa_ok $schema->resultset('Artist'), 'A::Useless', 'Artist RS';
+ok !$schema->resultset('CD')->isa('A::Useless'), 'CD RS is not A::Useless';
+
+done_testing;