=cut
sub register_source {
- my ($self, $moniker, $source) = @_;
+ my $self = shift;
+
+ $self->_register_source(@_);
+}
+
+=head2 register_extra_source
+
+=over 4
+
+=item Arguments: $moniker, $result_source
+
+=back
+
+As L</register_source> but should be used if the result class already
+has a source and you want to register an extra one.
+
+=cut
+
+sub register_extra_source {
+ my $self = shift;
+
+ $self->_register_source(@_, { extra => 1 });
+}
+
+sub _register_source {
+ my ($self, $moniker, $source, $params) = @_;
%$source = %{ $source->new( { %$source, source_name => $moniker }) };
$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}) {
+ warn $source->result_class . ' already has a source, use register_extra_source for additional sources';
+ }
$map{$source->result_class} = $moniker;
$self->class_mappings(\%map);
}
}
$class->ensure_class_loaded($comp_class);
- $comp = $comp_class->source_name || $comp;
-# $DB::single = 1;
+ my $snsub = $comp_class->can('source_name');
+ if(! $snsub ) {
+ warn "Failed to load $comp_class. Can't find source_name method. Is $comp_class really a full DBIC result class? Fix it, move it elsewhere, or make your load_classes call more specific.";
+ next;
+ }
+ $comp = $snsub->($comp_class) || $comp;
+
push(@to_register, [ $comp, $comp_class ]);
}
}
=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) = @_;
my $schema = $self->clone;
{
no warnings qw/redefine/;
- local *Class::C3::reinitialize = sub { };
+# local *Class::C3::reinitialize = sub { };
foreach my $moniker ($schema->sources) {
my $source = $schema->source($moniker);
my $target_class = "${target}::${moniker}";
$source->result_class($target_class);
$target_class->result_source_instance($source)
if $target_class->can('result_source_instance');
+ $schema->register_source($moniker, $source);
}
}
- Class::C3->reinitialize();
+# 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(@_) };
+ *{"${target}::${meth}"} =
+ sub { shift->schema->$meth(@_) };
}
}
return $schema;
my $clone = { (ref $self ? %$self : ()) };
bless $clone, (ref $self || $self);
+ $clone->class_mappings({ %{$clone->class_mappings} });
+ $clone->source_registrations({ %{$clone->source_registrations} });
foreach my $moniker ($self->sources) {
my $source = $self->source($moniker);
my $new = $source->new($source);
- $clone->register_source($moniker => $new);
+ # we use extra here as we want to leave the class_mappings as they are
+ # but overwrite the source_registrations entry with the new source
+ $clone->register_extra_source($moniker => $new);
}
$clone->storage->set_schema($clone) if $clone->storage;
return $clone;
=over 4
-=item Arguments: $rdbms_type
+=item Arguments: $rdbms_type, $sqlt_args, $dir
=back
-Returns the SQL statements used by L</deploy> and L<DBIx::Class::Schema/deploy>.
-C<$rdbms_type> provides the DBI database driver name for which the SQL
-statements are produced. If not supplied, the type of the current schema storage
-will be used.
+A convenient shortcut to storage->deployment_statements(). Returns the SQL statements
+used by L</deploy> and L<DBIx::Class::Schema::Storage/deploy>. C<$rdbms_type> provides
+the (optional) SQLT (not DBI) database driver name for which the SQL statements are produced.
+If not supplied, the type is determined by interrogating the current connection.
+The other two arguments are identical to those of L</deploy>.
=cut
sub deployment_statements {
- my ($self, $rdbms_type) = @_;
+ my $self = shift;
$self->throw_exception("Can't generate deployment statements without a storage")
if not $self->storage;
- $self->storage->deployment_statements($self, $rdbms_type);
+ $self->storage->deployment_statements($self, @_);
}
=head2 create_ddl_dir (EXPERIMENTAL)