package DBIx::Class::DB;
use base qw/Class::Data::Inheritable/;
+use DBIx::Class::Storage::DBI;
+use DBIx::Class::ClassResolver::PassThrough;
use DBI;
-__PACKAGE__->mk_classdata('_dbi_connect_info');
-__PACKAGE__->mk_classdata('_dbi_connect_package');
-__PACKAGE__->mk_classdata('_dbh');
-
=head1 NAME
-DBIx::Class::DB - DBIx::Class Database connection
+DBIx::Class::DB - Simple DBIx::Class Database connection by class inheritance
=head1 SYNOPSIS
+ package MyDB;
+
+ use base qw/DBIx::Class/;
+ __PACKAGE__->load_components('DB');
+
+ __PACKAGE__->connection('dbi:...', 'user', 'pass', \%attrs);
+
+ package MyDB::MyTable;
+
+ use base qw/MyDB/;
+ __PACKAGE__->load_components('Core');
+
+ ...
+
=head1 DESCRIPTION
-This class represents the connection to the database
+This class provides a simple way of specifying a database connection.
=head1 METHODS
=cut
-sub _get_dbh {
- my ($class) = @_;
- my $dbh;
- unless (($dbh = $class->_dbh) && $dbh->FETCH('Active') && $dbh->ping) {
- $class->_populate_dbh;
- }
- return $class->_dbh;
-}
-
-sub _populate_dbh {
- my ($class) = @_;
- my @info = @{$class->_dbi_connect_info || []};
- my $pkg = $class->_dbi_connect_package || $class;
- $pkg->_dbh($class->_dbi_connect(@info));
-}
-
-sub _dbi_connect {
- my ($class, @info) = @_;
- return DBI->connect(@info);
-}
+__PACKAGE__->mk_classdata('storage');
+__PACKAGE__->mk_classdata('class_resolver' =>
+ 'DBIx::Class::ClassResolver::PassThrough');
=item connection
sub connection {
my ($class, @info) = @_;
- $class->_dbi_connect_package($class);
- $class->_dbi_connect_info(\@info);
+ my $storage = DBIx::Class::Storage::DBI->new;
+ $storage->connect_info(\@info);
+ $class->storage($storage);
}
=item dbi_commit
=cut
-sub dbi_commit { $_[0]->_get_dbh->commit; }
+sub dbi_commit { $_[0]->storage->commit; }
=item dbi_rollback
=cut
-sub dbi_rollback { $_[0]->_get_dbh->rollback; }
+sub dbi_rollback { $_[0]->storage->rollback; }
+
+sub resolve_class { return shift->class_resolver->class(@_); }
1;
=head1 AUTHORS
-Matt S. Trout <perl-stuff@trout.me.uk>
+Matt S. Trout <mst@shadowcatsystems.co.uk>
=head1 LICENSE