sub add_columns {
my ($class, @cols) = @_;
- $class->table_instance->add_columns(map lc, @cols);
+ $class->result_source->add_columns(map lc, @cols);
$class->_mk_column_accessors(@cols);
}
$class->_column_groups($groups);
}
-sub all_columns { return shift->table_instance->columns; }
+sub all_columns { return shift->result_source->columns; }
sub primary_column {
my ($class) = @_;
package DBIx::Class::DB;
use base qw/DBIx::Class/;
+use DBIx::Class::Schema;
use DBIx::Class::Storage::DBI;
use DBIx::Class::ClassResolver::PassThrough;
use DBI;
*dbi_commit = \&txn_commit;
*dbi_rollback = \&txn_rollback;
-sub storage { shift->storage_instance(@_); }
+sub storage { shift->schema_instance(@_)->storage; }
sub resultset_instance {
my $class = shift;
- my $table = $class->table_instance->new($class->table_instance);
- $table->schema($class);
- $table->result_class($class);
- return $table->resultset;
-}
-
-sub result_source {
- my $class = shift;
- my $table = $class->table_instance->new($class->table_instance);
- $table->schema($class);
- $table->result_class($class);
- return $table;
+ my $source = $class->result_source;
+ if ($source->result_class ne $class) {
+ $source = $source->new($source);
+ $source->result_class($class);
+ }
+ return $source->resultset;
}
=head1 NAME
Sets or gets the storage backend. Defaults to L<DBIx::Class::Storage::DBI>.
-=head2 class_resolver
+=head2 class_resolver ****DEPRECATED****
Sets or gets the class to use for resolving a class. Defaults to
L<DBIx::Class::ClassResolver::Passthrough>, which returns whatever you give
my ($class, @info) = @_;
my $storage = DBIx::Class::Storage::DBI->new;
$storage->connect_info(\@info);
- $class->mk_classdata('storage_instance' => $storage);
+ my $schema = bless({ storage => $storage }, 'DBIx::Class::Schema');
+ $class->mk_classdata('schema_instance' => $schema);
}
=head2 txn_begin
sub txn_rollback { $_[0]->storage->txn_rollback }
-sub resolve_class { return shift->class_resolver->class(@_); }
+sub resolve_class {
+ warn "resolve_class deprecated as of 0.04999_02";
+ return shift->class_resolver->class(@_);
+}
1;
#use Data::Dumper; warn Dumper($query);
#warn $rel_obj->{class}." $meth $cond ".join(', ', @{$attrs->{bind}||[]});
delete $attrs->{_action};
- return $self->resolve_class($rel_obj->{class}
+ return $self->result_source->schema->resultset($rel_obj->{class}
)->search($query, $attrs);
}
$self->throw( "set_from_related can only handle a hash condition; the "
."condition for $rel is of type ".(ref $cond ? ref $cond : 'plain scalar'))
unless ref $cond eq 'HASH';
- my $f_class = $self->resolve_class($rel_obj->{class});
+ my $f_class = $self->result_source->schema->class($rel_obj->{class});
$self->throw( "Object $f_obj isn't a ".$f_class )
unless $f_obj->isa($f_class);
foreach my $key (keys %$cond) {
sub inflate_result {
my ($class, $me, $prefetch) = @_;
#use Data::Dumper; print Dumper(@_);
- my $new = bless({ _column_data => $me }, ref $class || $class);
- $new->in_storage(1);
+ my $new = bless({ _column_data => $me, _in_storage => 1 },
+ ref $class || $class);
+ my $schema;
PRE: foreach my $pre (keys %{$prefetch||{}}) {
my $rel_obj = $class->_relationships->{$pre};
- my $pre_class = $class->resolve_class($rel_obj->{class});
+ $schema ||= $new->result_source->schema;
+ my $pre_class = $schema->class($rel_obj->{class});
my $fetched = $pre_class->inflate_result(@{$prefetch->{$pre}});
$class->throw("No accessor for prefetched $pre")
unless defined $rel_obj->{attrs}{accessor};
=cut
sub register_class {
- my ($class, $name, $to_register) = @_;
- my %reg = %{$class->class_registrations};
+ my ($self, $name, $to_register) = @_;
+ my %reg = %{$self->class_registrations};
$reg{$name} = $to_register;
- $class->class_registrations(\%reg);
+ $self->class_registrations(\%reg);
+ $to_register->result_source->schema($self);
}
=head2 registered_classes
__PACKAGE__->mk_classdata('table_class' => 'DBIx::Class::Table');
-sub iterator_class { shift->table_instance->resultset_class(@_) }
-sub resultset_class { shift->table_instance->resultset_class(@_) }
-sub _table_name { shift->table_instance->name }
+sub iterator_class { shift->result_source->resultset_class(@_) }
+sub resultset_class { shift->result_source->resultset_class(@_) }
+sub _table_name { shift->result_source->name }
=head1 NAME
sub add_columns {
my ($class, @cols) = @_;
- $class->table_instance->add_columns(@cols);
+ $class->result_source->add_columns(@cols);
$class->_mk_column_accessors(@cols);
}
sub _select_columns {
- return shift->table_instance->columns;
+ return shift->result_source->columns;
}
=head2 table
sub table {
my ($class, $table) = @_;
- return $class->table_instance->name unless $table;
+ return $class->result_source->name unless $table;
unless (ref $table) {
$table = $class->table_class->new(
{
name => $table,
result_class => $class,
});
- if ($class->can('table_instance')) {
- $table->{_columns} = { %{$class->table_instance->{_columns}||{}} };
+ if ($class->can('result_source')) {
+ $table->{_columns} = { %{$class->result_source->{_columns}||{}} };
}
}
- $class->mk_classdata('table_instance' => $table);
+ $class->mk_classdata('result_source' => $table);
+ if ($class->can('schema_instance')) {
+ $class =~ m/([^:]+)$/;
+ $class->schema_instance->register_class($class, $class);
+ }
}
=head2 has_column
sub has_column {
my ($self, $column) = @_;
- return $self->table_instance->has_column($column);
+ return $self->result_source->has_column($column);
}
=head2 column_info
sub column_info {
my ($self, $column) = @_;
- return $self->table_instance->column_info($column);
+ return $self->result_source->column_info($column);
}
=head2 columns
=cut
sub columns {
- return shift->table_instance->columns(@_);
+ return shift->result_source->columns(@_);
}
-sub set_primary_key { shift->table_instance->set_primary_key(@_); }
-sub primary_columns { shift->table_instance->primary_columns(@_); }
+sub set_primary_key { shift->result_source->set_primary_key(@_); }
+sub primary_columns { shift->result_source->primary_columns(@_); }
1;
package CDBase;
use strict;
-use base qw(DBIx::Class);
-__PACKAGE__->load_components(qw/CDBICompat Core DB/);
-
-use File::Temp qw/tempfile/;
-my (undef, $DB) = tempfile();
-my @DSN = ("dbi:SQLite:dbname=$DB", '', '', { AutoCommit => 1 });
-
-END { unlink $DB if -e $DB }
-
-__PACKAGE__->connection(@DSN);
+use base qw(DBIx::Class::Test::SQLite);
1;