X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FDBIx%2FClass%2FSchema.pm;h=3e9d93e7b683a1a961e0fba934f73efbb2999ef4;hb=5b0b4df82267d761f34c606a1f97b6950a2eed4a;hp=55763782579c81117a4b0709a0ffdcca2561d010;hpb=6eec9003c0b7825a896bec4e87b4139443b8bf88;p=dbsrgits%2FDBIx-Class.git diff --git a/lib/DBIx/Class/Schema.pm b/lib/DBIx/Class/Schema.pm index 5576378..3e9d93e 100644 --- a/lib/DBIx/Class/Schema.pm +++ b/lib/DBIx/Class/Schema.pm @@ -615,26 +615,53 @@ will produce the output =cut +# this might be oversimplified +# sub compose_namespace { +# my ($self, $target, $base) = @_; + +# my $schema = $self->clone; +# foreach my $moniker ($schema->sources) { +# my $source = $schema->source($moniker); +# my $target_class = "${target}::${moniker}"; +# $self->inject_base( +# $target_class => $source->result_class, ($base ? $base : ()) +# ); +# $source->result_class($target_class); +# $target_class->result_source_instance($source) +# if $target_class->can('result_source_instance'); +# $schema->register_source($moniker, $source); +# } +# return $schema; +# } + sub compose_namespace { my ($self, $target, $base) = @_; - - $self = $self->clone; - foreach my $moniker ($self->sources) { - my $source = $self->source($moniker); - my $source_class = ref $source; - my $source_copy = $source_class->new({ - %$source, - _relationships => Storable::dclone( $source->_relationships ), - }); - - my $target_class = "${target}::${moniker}"; - $self->inject_base( - $target_class => $source_copy->result_class, ($base ? $base : ()) - ); - $source_copy->result_class($target_class); - $self->register_source($moniker, $source_copy); + my $schema = $self->clone; + { + no warnings qw/redefine/; +# local *Class::C3::reinitialize = sub { }; + foreach my $moniker ($schema->sources) { + my $source = $schema->source($moniker); + my $target_class = "${target}::${moniker}"; + $self->inject_base( + $target_class => $source->result_class, ($base ? $base : ()) + ); + $source->result_class($target_class); + $target_class->result_source_instance($source) + if $target_class->can('result_source_instance'); + $schema->register_source($moniker, $source); + } } - return $self; +# Class::C3->reinitialize(); + { + no strict 'refs'; + no warnings 'redefine'; + foreach my $meth (qw/class source resultset/) { + *{"${target}::${meth}"} = + sub { shift->schema->$meth(@_) }; + } + } + return $schema; } sub setup_connection_class {