use strict;
use warnings;
-use base qw/DBIx::Class::CDBICompat DBIx::Class::Core/;
-
use vars qw($VERSION);
+use base;
$VERSION = '0.01';
+sub load_components {
+ my $class = shift;
+ my @comp = map { "DBIx::Class::$_" } @_;
+ foreach my $comp (@comp) {
+ eval "use $comp";
+ die $@ if $@;
+ }
+ no strict 'refs';
+ unshift(@{"${class}::ISA"}, @comp);
+}
+
1;
=head1 NAME
with
-use base qw/DBIx::Class::CDBICompat DBIx::Class::Core/;
+use base qw/DBIx::Class/;
+__PACKAGE__->load_components(qw/CDBICompat Core/);
will probably get you started.
If you're using AUTO_INCREMENT for your primary columns, you'll also want
-PK::Auto and an appropriate PK::Auto::DBName (e.g. ::SQLite).
+yo load the approriate PK::Auto subclass - e.g.
+
+__PACKAGE__->load_components(qw/CDBICompat PK::Auto::SQLite Core/);
+
+(with is what ::Test::SQLite does to present the Class::DBI::Test::SQLite
+interface)
If you fancy playing around with DBIx::Class from scratch, then read the docs
for ::Table and ::Relationship,
use base qw/DBIx::Class/;
+__PACKAGE__->load_components(qw/Core/);
and have a look at t/lib/DBICTest.pm for a brief example.
use strict;
use warnings;
-
-use base qw/DBIx::Class::CDBICompat::Constraints
- DBIx::Class::CDBICompat::Triggers
- DBIx::Class::CDBICompat::ReadOnly
- DBIx::Class::CDBICompat::GetSet
- DBIx::Class::CDBICompat::LiveObjectIndex
- DBIx::Class::CDBICompat::AttributeAPI
- DBIx::Class::CDBICompat::Stringify
- DBIx::Class::CDBICompat::DestroyWarning
- DBIx::Class::CDBICompat::Constructor
- DBIx::Class::CDBICompat::AccessorMapping
- DBIx::Class::CDBICompat::ColumnCase
- DBIx::Class::CDBICompat::MightHave
- DBIx::Class::CDBICompat::HasMany
- DBIx::Class::CDBICompat::HasA
- DBIx::Class::CDBICompat::LazyLoading
- DBIx::Class::CDBICompat::AutoUpdate
- DBIx::Class::CDBICompat::TempColumns
- DBIx::Class::CDBICompat::ColumnGroups
- DBIx::Class::CDBICompat::ImaDBI/;
+use base qw/DBIx::Class/;
+
+__PACKAGE__->load_components(qw/
+ CDBICompat::Constraints
+ CDBICompat::Triggers
+ CDBICompat::ReadOnly
+ CDBICompat::GetSet
+ CDBICompat::LiveObjectIndex
+ CDBICompat::AttributeAPI
+ CDBICompat::Stringify
+ CDBICompat::DestroyWarning
+ CDBICompat::Constructor
+ CDBICompat::AccessorMapping
+ CDBICompat::ColumnCase
+ CDBICompat::MightHave
+ CDBICompat::HasMany
+ CDBICompat::HasA
+ CDBICompat::LazyLoading
+ CDBICompat::AutoUpdate
+ CDBICompat::TempColumns
+ CDBICompat::ColumnGroups
+ CDBICompat::ImaDBI/);
#DBIx::Class::CDBICompat::ObjIndexStubs
1;
if $too_many;
$self->add_relationship($col, $f_class,
{ "foreign.${pri}" => "self.${col}" },
- { _type => 'has_a', accessor => 'filter' } );
+ { accessor => 'filter' } );
return 1;
}
use strict;
use warnings;
-use base qw/DBIx::Class::Relationship::Accessor
- DBIx::Class::Relationship::CascadeActions
- DBIx::Class::Relationship::ProxyMethods
- DBIx::Class::Relationship
- DBIx::Class::InflateColumn
- DBIx::Class::SQL::OrderBy
- DBIx::Class::SQL::Abstract
- DBIx::Class::PK
- DBIx::Class::Table
- DBIx::Class::SQL
- DBIx::Class::DB
- DBIx::Class::Exception
- DBIx::Class::AccessorGroup/;
+use base qw/DBIx::Class/;
+
+__PACKAGE__->load_components(qw/
+ Relationship::Accessor
+ Relationship::CascadeActions
+ Relationship::ProxyMethods
+ Relationship
+ InflateColumn
+ SQL::OrderBy
+ SQL::Abstract
+ PK
+ Table
+ SQL
+ DB
+ Exception
+ AccessorGroup/);
1;
=head1 DESCRIPTION
This class just inherits from the various modules that makes
-up the Class::DBI core features.
+up the DBIx::Class core features.
=head1 AUTHORS
if $too_many;
unless (defined $self->get_column($pri)) {
$self->throw( "Can't auto-inc for $pri on ".ref $self.": no _last_insert_id method" )
- unless $self->can('_last_insert_id');
- my $id = $self->_last_insert_id;
+ unless $self->can('last_insert_id');
+ my $id = $self->last_insert_id;
$self->throw( "Can't get last insert id" ) unless $id;
$self->store_column($pri => $id);
}
use strict;
use warnings;
-sub _last_insert_id {
+use base qw/DBIx::Class/;
+
+__PACKAGE__->load_components(qw/PK::Auto/);
+
+sub last_insert_id {
return $_[0]->_get_dbh->func('last_insert_rowid');
}
return $new->insert;
}
-sub _cond_resolve {
- my ($self, $query, $attrs) = @_;
- return '1 = 1' unless keys %$query;
- my $op = $attrs->{'cmp'} || '=';
- my $cond = join(' AND ',
- map { (defined $query->{$_}
- ? "$_ $op ?"
- : (do { delete $query->{$_}; "$_ IS NULL"; }));
- } keys %$query);
- return ($cond, values %$query);
-}
+#sub _cond_resolve {
+# my ($self, $query, $attrs) = @_;
+# return '1 = 1' unless keys %$query;
+# my $op = $attrs->{'cmp'} || '=';
+# my $cond = join(' AND ',
+# map { (defined $query->{$_}
+# ? "$_ $op ?"
+# : (do { delete $query->{$_}; "$_ IS NULL"; }));
+# } keys %$query);
+# return ($cond, values %$query);
+#}
=item table
use strict;
-use base qw/DBIx::Class::CDBICompat DBIx::Class::PK::Auto::SQLite DBIx::Class::PK::Auto DBIx::Class::Core/;
+use base qw/DBIx::Class/;
+
+__PACKAGE__->load_components(qw/CDBICompat PK::Auto::SQLite Core/);
+
use File::Temp qw/tempfile/;
my (undef, $DB) = tempfile();
END { unlink $DB if -e $DB }
-my @DSN = ("dbi:SQLite:dbname=$DB", '', '', { AutoCommit => 1 });
+my @DSN = ("dbi:SQLite:dbname=$DB", '', '', { AutoCommit => 1, RaiseError => 1 });
__PACKAGE__->connection(@DSN);
__PACKAGE__->set_sql(_table_pragma => 'PRAGMA table_info(__TABLE__)');
use Test::More;
-use DBIx::Class::PK::Auto;
-use DBIx::Class::PK::Auto::SQLite;
-
plan tests => 2;
use lib qw(t/lib);
use_ok('DBICTest');
-unshift(@DBICTest::Artist::ISA, qw/DBIx::Class::PK::Auto
- DBIx::Class::PK::Auto::SQLite/);
+DBICTest::Artist->load_components(qw/PK::Auto::SQLite/);
# add an artist without primary key to test Auto
my $artist = DBICTest::Artist->create( { name => 'Auto' } );
package State;
use base 'DBIx::Class';
+State->load_components(qw/CDBICompat Core/);
State->table('State');
State->columns(Essential => qw/Abbreviation Name/);
package City;
use base 'DBIx::Class';
+City->load_components(qw/CDBICompat Core/);
City->table('City');
City->columns(All => qw/Name State Population/);
#-------------------------------------------------------------------------
package CD;
use base 'DBIx::Class';
+CD->load_components(qw/CDBICompat Core/);
CD->table('CD');
CD->columns('All' => qw/artist title length/);
}
{
+ package DieTest;
+ @DieTest::ISA = qw(DBIx::Class);
+ DieTest->load_components(qw/Core/);
+ package main;
local $SIG{__WARN__} = sub { };
- eval { DBIx::Class->retrieve(1) };
+ eval { DieTest->retrieve(1) };
like $@, qr/Can't retrieve unless primary columns are defined/, "Need primary key for retrieve";
}
package A;
@A::ISA = qw(DBIx::Class);
+__PACKAGE__->load_components(qw/CDBICompat Core/);
__PACKAGE__->columns(Primary => 'id');
package A::B;
package A;
@A::ISA = qw(DBIx::Class);
+__PACKAGE__->load_components(qw/CDBICompat Core/);
__PACKAGE__->columns(Primary => 'id');
package A::B;
use strict;
use base qw(DBIx::Class);
+__PACKAGE__->load_components(qw/CDBICompat Core/);
use File::Temp qw/tempfile/;
my (undef, $DB) = tempfile();