[Bast-commits] r4738 - in DBIx-Class/0.08/trunk: lib/DBIx/Class t
lukes at dev.catalyst.perl.org
lukes at dev.catalyst.perl.org
Thu Aug 7 01:07:20 BST 2008
Author: lukes
Date: 2008-08-07 01:07:20 +0100 (Thu, 07 Aug 2008)
New Revision: 4738
Modified:
DBIx-Class/0.08/trunk/lib/DBIx/Class/Schema.pm
DBIx-Class/0.08/trunk/t/47bind_attribute.t
Log:
refactored compose_namepspace
Modified: DBIx-Class/0.08/trunk/lib/DBIx/Class/Schema.pm
===================================================================
--- DBIx-Class/0.08/trunk/lib/DBIx/Class/Schema.pm 2008-08-06 20:11:39 UTC (rev 4737)
+++ DBIx-Class/0.08/trunk/lib/DBIx/Class/Schema.pm 2008-08-07 00:07:20 UTC (rev 4738)
@@ -131,12 +131,12 @@
$self->source_registrations(\%reg);
$source->schema($self);
-
weaken($source->{schema}) if ref($self);
+ return if ($params->{extra});
+
if ($source->result_class) {
my %map = %{$self->class_mappings};
if (exists $map{$source->result_class}) {
- return if ($params->{extra});
warn $source->result_class . ' already has a source, use register_extra_source for additional sources';
}
$map{$source->result_class} = $moniker;
@@ -617,31 +617,24 @@
sub compose_namespace {
my ($self, $target, $base) = @_;
- 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');
- }
+
+ $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);
}
- Class::C3->reinitialize();
- {
- no strict 'refs';
- no warnings 'redefine';
- foreach my $meth (qw/class source resultset/) {
- my $name = join '::', $target, $meth;
- *$name = Sub::Name::subname $name, sub { shift->schema->$meth(@_) };
- }
- }
- return $schema;
+ return $self;
}
sub setup_connection_class {
Modified: DBIx-Class/0.08/trunk/t/47bind_attribute.t
===================================================================
--- DBIx-Class/0.08/trunk/t/47bind_attribute.t 2008-08-06 20:11:39 UTC (rev 4737)
+++ DBIx-Class/0.08/trunk/t/47bind_attribute.t 2008-08-07 00:07:20 UTC (rev 4738)
@@ -60,7 +60,7 @@
join cd on cd.artist=a.artistid
where cd.year=?)
-$schema->register_source('Complex' => $new_source);
+$schema->register_extra_source('Complex' => $new_source);
$rs = $schema->resultset('Complex')->search({}, { bind => [ 1999 ] });
is ( $rs->count, 1, 'cookbook arbitrary sql example' );
More information about the Bast-commits
mailing list