use strict;
use warnings;
+
+use Carp qw/croak/;
use UNIVERSAL::require;
use base qw/DBIx::Class/;
__PACKAGE__->load_components(qw/Exception/);
__PACKAGE__->mk_classdata('class_mappings' => {});
__PACKAGE__->mk_classdata('source_registrations' => {});
-__PACKAGE__->mk_classdata('storage_type' => 'DBI');
+__PACKAGE__->mk_classdata('storage_type' => '::DBI');
__PACKAGE__->mk_classdata('storage');
=head1 NAME
=head1 SYNOPSIS
-in My/Schema.pm
-
package My::Schema;
-
use base qw/DBIx::Class::Schema/;
-
+
+ # load My::Schema::Foo, My::Schema::Bar, My::Schema::Baz
__PACKAGE__->load_classes(qw/Foo Bar Baz/);
-in My/Schema/Foo.pm
-
package My::Schema::Foo;
-
use base qw/DBIx::Class/;
-
__PACKAGE__->load_components(qw/PK::Auto::Pg Core/); # for example
__PACKAGE__->table('foo');
- ...
-
-in My/DB.pm
-
- use My::Schema;
- My::Schema->compose_connection('My::DB', $dsn, $user, $pass, $attrs);
+ my $schema1 = My::Schema->connect(
+ $dsn,
+ $user,
+ $password,
+ $attrs
+ );
-then in app code
+ my $schema2 = My::Schema->connect( ... );
- my @obj = My::DB::Foo->search({}); # My::DB::Foo isa My::Schema::Foo My::DB
+ # fetch objects using My::Schema::Foo
+ my $resultset = $schema1->resultset('Foo')->search( ... );
+ my @objects = $schema2->resultset('Foo')->search( ... );
=head1 DESCRIPTION
-Creates database classes based on a schema. This allows you to have more than
-one concurrent connection using the same database classes, by making
-subclasses under a new namespace for each connection. If you only need one
-class, you should probably use L<DBIx::Class::DB> directly instead.
+Creates database classes based on a schema. This is the recommended way to
+use L<DBIx::Class> and allows you to use more than one concurrent connection
+with your classes.
NB: If you're used to L<Class::DBI> it's worth reading the L</SYNOPSIS>
carefully as DBIx::Class does things a little differently. Note in
=head2 register_class <moniker> <component_class>
-Registers a class which isa ResultSourceInstance; equivalent to calling
+Registers a class which isa ResultSourceProxy; equivalent to calling
$schema->register_source($moniker, $class->result_source_instance);
# if we got here, they probably passed a full class name
my $mapped = $self->class_mappings->{$moniker};
- die "Can't find source for ${moniker}"
+ croak "Can't find source for ${moniker}"
unless $mapped && exists $sreg->{$mapped};
return $sreg->{$mapped};
}
sub compose_connection {
my ($self, $target, @info) = @_;
- my $base = 'DBIx::Class::ResultSetInstance';
+ my $base = 'DBIx::Class::ResultSetProxy';
$base->require;
my $schema = $self->compose_namespace($target, $base);
$schema->connection(@info);
=head2 connection(@args)
Instantiates a new Storage object of type storage_type and passes the
-arguments to $storage->connection_info. Sets the connection in-place on
+arguments to $storage->connect_info. Sets the connection in-place on
the schema.
=cut
sub connection {
my ($self, @info) = @_;
- my $storage_class = 'DBIx::Class::Storage::'.$self->storage_type;
+ my $storage_class = $self->storage_type;
+ $storage_class = 'DBIx::Class::Storage'.$storage_class
+ if $storage_class =~ m/^::/;
$storage_class->require;
my $storage = $storage_class->new;
$storage->connect_info(\@info);