# avoid OS X finder files
\.DS_Store$
-# Don't ship the test db
-^t/var
+# Don't ship the test junk
+^t/_dump
+^t/dbictest.db
# Don't ship the last dist we built :)
\.tar\.gz$
use warnings;
use base qw/DBIx::Class::Schema/;
use base qw/Class::Data::Accessor/;
-use Carp::Clan qw/^DBIx::Class::Schema::Loader/;
+use Carp::Clan qw/^DBIx::Class/;
use UNIVERSAL::require;
use Class::C3;
use Scalar::Util qw/ weaken /;
reasons. If you do not wish to change any options, just call it
with an empty argument list during schema class initialization.
-You should either specify this method before setting the connection
-information for your schema, or specify these options as a part of
-your connection information (see below). For now it will merely
-warn if the ordering is wrong, but in the future this will cause problems.
+Setting these options explicitly via this method B<after> calling
+C<connection> is deprecated and will stop working in version 0.04000.
+For now the code merely warns about this condition.
+
+The preferred way of doing things is to either call C<loader_options>
+before any connection is made, or embed the C<loader_options> in
+the connection information itself as shown below.
=cut
$self->_loader_args(\%args);
if($self->storage && !$class->loader) {
- warn "Do not set loader_options after specifying the connection info";
+ warn "Do not set loader_options after specifying the connection info,"
+ . " this will be unsupported in 0.04000";
$self->_invoke_loader;
}
$self = $self->next::method(@_);
my $class = ref $self || $self;
- $self->_invoke_loader if $self->_loader_args && !$class->loader;
+ if($self->_loader_args && !$class->loader) {
+ $self->_invoke_loader
+ }
+ else {
+ warn "loader_options should be set before connecting the "
+ . "schema, see the DBIx::Class::Schema::Loader docs";
+ }
return $self;
}
sub clone {
my $self = shift;
- croak "You failed to specify the required loader_options"
- if !$self->_loader_args;
-
my $clone = $self->next::method(@_);
- $clone->_loader_args($self->_loader_args);
- $clone->_loader_args->{schema} = $clone;
- weaken($clone->_loader_args->{schema});
+ if($clone->_loader_args) {
+ $clone->_loader_args->{schema} = $clone;
+ weaken($clone->_loader_args->{schema});
+ }
$clone;
}
use warnings;
use base qw/Class::Accessor::Fast/;
use Class::C3;
-use Carp::Clan qw/^DBIx::Class::Schema::Loader/;
+use Carp::Clan qw/^DBIx::Class/;
use UNIVERSAL::require;
use DBIx::Class::Schema::Loader::RelBuilder;
use Data::Dump qw/ dump /;
my $schema_fn = $self->_get_dump_filename($schema_class);
croak "$schema_fn exists, will not overwrite"
if -f $schema_fn && !$self->dump_overwrite;
- sysopen(my $schema_fh, '>', $schema_fn)
+ open(my $schema_fh, '>', $schema_fn)
or croak "Cannot open $schema_fn for writing: $!";
print $schema_fh qq|package $schema_class;\n\n$tagline\n\n|;
print $schema_fh qq|use strict;\nuse warnings;\n\n|;
use warnings;
use base qw/DBIx::Class::Schema::Loader::Base Class::Accessor::Fast/;
use Class::C3;
-use Carp::Clan qw/^DBIx::Class::Schema::Loader/;
+use Carp::Clan qw/^DBIx::Class/;
use UNIVERSAL::require;
=head1 NAME
use strict;
use warnings;
use base 'DBIx::Class::Schema::Loader::DBI';
-use Carp::Clan qw/^DBIx::Class::Schema::Loader/;
+use Carp::Clan qw/^DBIx::Class/;
use Class::C3;
=head1 NAME
use strict;
use warnings;
use base 'DBIx::Class::Schema::Loader::DBI';
-use Carp::Clan qw/^DBIx::Class::Schema::Loader/;
+use Carp::Clan qw/^DBIx::Class/;
use Class::C3;
=head1 NAME
use strict;
use warnings;
use base qw/DBIx::Class::Schema::Loader::DBI/;
-use Carp::Clan qw/^DBIx::Class::Schema::Loader/;
+use Carp::Clan qw/^DBIx::Class/;
use Text::Balanced qw( extract_bracketed );
use Class::C3;
use strict;
use warnings;
use base 'DBIx::Class::Schema::Loader::DBI';
- use Carp::Clan qw/^DBIx::Class::Schema::Loader/;
+ use Carp::Clan qw/^DBIx::Class/;
use Class::C3;
sub _table_uniq_info {
use strict;
use warnings;
use base 'DBIx::Class::Schema::Loader::DBI';
-use Carp::Clan qw/^DBIx::Class::Schema::Loader/;
+use Carp::Clan qw/^DBIx::Class/;
use Class::C3;
=head1 NAME
use strict;
use warnings;
-use Carp::Clan qw/^DBIx::Class::Schema::Loader/;
+use Carp::Clan qw/^DBIx::Class/;
use Lingua::EN::Inflect ();
use Lingua::EN::Inflect::Number ();
--- /dev/null
+use strict;
+use Test::More;
+use lib qw(t/lib);
+use make_dbictest_db;
+
+# Takes a $schema as input, runs 4 basic tests
+sub test_schema {
+ my ($testname, $schema) = @_;
+
+ $schema = $schema->clone if !ref $schema;
+ isa_ok($schema, 'DBIx::Class::Schema', $testname);
+
+ my $foo_rs = $schema->resultset('Bar')->search({ barid => 3})->search_related('fooref');
+ isa_ok($foo_rs, 'DBIx::Class::ResultSet', $testname);
+
+ my $foo_first = $foo_rs->first;
+ like(ref $foo_first, qr/DBICTest::Schema::\d+::Foo/, $testname);
+
+ my $foo_first_text = $foo_first->footext;
+ is($foo_first_text, 'Foo record associated with the Bar with barid 3');
+}
+
+my @invocations = (
+ 'deprecated_one' => sub {
+ package DBICTest::Schema::1;
+ use base qw/ DBIx::Class::Schema::Loader /;
+ __PACKAGE__->connection($make_dbictest_db::dsn);
+ __PACKAGE__->load_from_connection( relationships => 1 );
+ __PACKAGE__;
+ },
+ 'deprecated_two' => sub {
+ package DBICTest::Schema::2;
+ use base qw/ DBIx::Class::Schema::Loader /;
+ __PACKAGE__->load_from_connection(
+ relationships => 1,
+ connect_info => [ $make_dbictest_db::dsn ],
+ );
+ __PACKAGE__;
+ },
+ 'deprecated_three' => sub {
+ package DBICTest::Schema::3;
+ use base qw/ DBIx::Class::Schema::Loader /;
+ __PACKAGE__->load_from_connection(
+ relationships => 1,
+ dsn => $make_dbictest_db::dsn,
+ );
+ __PACKAGE__;
+ },
+ 'deprecated_four' => sub {
+ package DBICTest::Schema::4;
+ use base qw/ DBIx::Class::Schema::Loader /;
+ __PACKAGE__->connection($make_dbictest_db::dsn);
+ __PACKAGE__->loader_options( relationships => 1 );
+ __PACKAGE__;
+ },
+ 'hardcode' => sub {
+ package DBICTest::Schema::5;
+ use base qw/ DBIx::Class::Schema::Loader /;
+ __PACKAGE__->loader_options( relationships => 1 );
+ __PACKAGE__->connection($make_dbictest_db::dsn);
+ __PACKAGE__;
+ },
+ 'normal' => sub {
+ package DBICTest::Schema::6;
+ use base qw/ DBIx::Class::Schema::Loader /;
+ __PACKAGE__->loader_options( relationships => 1 );
+ __PACKAGE__->connect($make_dbictest_db::dsn);
+ },
+ 'make_schema_at' => sub {
+ use DBIx::Class::Schema::Loader qw/ make_schema_at /;
+ make_schema_at(
+ 'DBICTest::Schema::7',
+ { relationships => 1 },
+ [ $make_dbictest_db::dsn ],
+ );
+ DBICTest::Schema::7->clone;
+ },
+ 'embedded_options' => sub {
+ package DBICTest::Schema::8;
+ use base qw/ DBIx::Class::Schema::Loader /;
+ __PACKAGE__->connect(
+ $make_dbictest_db::dsn,
+ { loader_options => { relationships => 1 } }
+ );
+ },
+ 'embedded_options_in_attrs' => sub {
+ package DBICTest::Schema::9;
+ use base qw/ DBIx::Class::Schema::Loader /;
+ __PACKAGE__->connect(
+ $make_dbictest_db::dsn,
+ undef,
+ undef,
+ { AutoCommit => 1, loader_options => { relationships => 1 } }
+ );
+ },
+ 'embedded_options_make_schema_at' => sub {
+ use DBIx::Class::Schema::Loader qw/ make_schema_at /;
+ make_schema_at(
+ 'DBICTest::Schema::10',
+ { },
+ [
+ $make_dbictest_db::dsn,
+ { loader_options => { relationships => 1 } },
+ ],
+ );
+ "DBICTest::Schema::10";
+ },
+ 'almost_embedded' => sub {
+ package DBICTest::Schema::11;
+ use base qw/ DBIx::Class::Schema::Loader /;
+ __PACKAGE__->loader_options( relationships => 1 );
+ __PACKAGE__->connect(
+ $make_dbictest_db::dsn,
+ undef, undef, { AutoCommit => 1 }
+ );
+ },
+ 'make_schema_at_explicit' => sub {
+ use DBIx::Class::Schema::Loader;
+ DBIx::Class::Schema::Loader::make_schema_at(
+ 'DBICTest::Schema::12',
+ { relationships => 1 },
+ [ $make_dbictest_db::dsn ],
+ );
+ DBICTest::Schema::12->clone;
+ }
+);
+
+# 4 tests per k/v pair
+plan tests => 2 * @invocations;
+
+while(@invocations >= 2) {
+ my $style = shift @invocations;
+ my $subref = shift @invocations;
+ test_schema($style, &$subref);
+}
+++ /dev/null
-use strict;
-use Test::More tests => 4;
-use lib qw(t/lib);
-use make_dbictest_db;
-
-eval { require DBD::SQLite };
-my $class = $@ ? 'SQLite2' : 'SQLite';
-
-package DBICTest::Schema;
-use base qw/ DBIx::Class::Schema::Loader /;
-
-__PACKAGE__->connection("dbi:$class:dbname=./t/dbictest.db");
-__PACKAGE__->load_from_connection( relationships => 1 );
-
-package main;
-
-my $schema_class = 'DBICTest::Schema';
-my $schema = $schema_class->clone;
-isa_ok($schema, 'DBIx::Class::Schema');
-
-my $foo_rs = $schema->resultset('Bar')->search({ barid => 3})->search_related('fooref');
-isa_ok($foo_rs, 'DBIx::Class::ResultSet');
-
-my $foo_first = $foo_rs->first;
-isa_ok($foo_first, 'DBICTest::Schema::Foo');
-
-my $foo_first_text = $foo_first->footext;
-is($foo_first_text, 'This is the text of the only Foo record associated with the Bar with barid 3');
-
+++ /dev/null
-use strict;
-use Test::More tests => 4;
-use lib qw(t/lib);
-use make_dbictest_db;
-
-eval { require DBD::SQLite };
-my $class = $@ ? 'SQLite2' : 'SQLite';
-
-package DBICTest::Schema;
-use base qw/ DBIx::Class::Schema::Loader /;
-
-__PACKAGE__->load_from_connection(
- relationships => 1,
- connect_info => [ "dbi:$class:dbname=./t/dbictest.db" ],
-);
-
-package main;
-
-my $schema_class = 'DBICTest::Schema';
-my $schema = $schema_class->clone;
-isa_ok($schema, 'DBIx::Class::Schema');
-
-my $foo_rs = $schema->resultset('Bar')->search({ barid => 3})->search_related('fooref');
-isa_ok($foo_rs, 'DBIx::Class::ResultSet');
-
-my $foo_first = $foo_rs->first;
-isa_ok($foo_first, 'DBICTest::Schema::Foo');
-
-my $foo_first_text = $foo_first->footext;
-is($foo_first_text, 'This is the text of the only Foo record associated with the Bar with barid 3');
-
--- /dev/null
+use strict;
+use Test::More;
+use lib qw(t/lib);
+use make_dbictest_db;
+
+{
+ $INC{'DBIx/Class/Storage/xyzzy.pm'} = 1;
+ package DBIx::Class::Storage::xyzzy;
+ use base qw/ DBIx::Class::Storage /;
+ sub new { bless {}, shift }
+ sub connect_info { @_ }
+
+ package DBICTest::Schema;
+ use base qw/ DBIx::Class::Schema::Loader /;
+ __PACKAGE__->loader_options( relationships => 1 );
+ __PACKAGE__->storage_type( '::xyzzy' );
+}
+
+plan tests => 1;
+
+eval { DBICTest::Schema->connect($make_dbictest_db::dsn) };
+like(
+ $@,
+ qr/Could not load storage_type loader "DBIx::Class::Schema::Loader::xyzzy": /,
+ 'Bad storage type dies correctly'
+);
--- /dev/null
+use strict;
+use Test::More;
+use lib qw(t/lib);
+use make_dbictest_db;
+
+{
+ package DBICTest::Schema;
+ use base qw/ DBIx::Class::Schema::Loader /;
+ __PACKAGE__->loader_options(
+ relationships => 1,
+ dump_directory => './t/_dump',
+ dump_overwrite => 1,
+ );
+
+}
+
+plan tests => 1;
+
+eval { DBICTest::Schema->connect($make_dbictest_db::dsn) };
+ok(!$@, 'no death with dump_directory set')
+ or diag "Dump failed: $@";
+++ /dev/null
-use strict;
-use Test::More tests => 4;
-use lib qw(t/lib);
-use make_dbictest_db;
-
-eval { require DBD::SQLite };
-my $class = $@ ? 'SQLite2' : 'SQLite';
-
-package DBICTest::Schema;
-use base qw/ DBIx::Class::Schema::Loader /;
-
-__PACKAGE__->load_from_connection(
- relationships => 1,
- dsn => "dbi:$class:dbname=./t/dbictest.db",
-);
-
-package main;
-
-my $schema_class = 'DBICTest::Schema';
-my $schema = $schema_class->clone;
-isa_ok($schema, 'DBIx::Class::Schema');
-
-my $foo_rs = $schema->resultset('Bar')->search({ barid => 3})->search_related('fooref');
-isa_ok($foo_rs, 'DBIx::Class::ResultSet');
-
-my $foo_first = $foo_rs->first;
-isa_ok($foo_first, 'DBICTest::Schema::Foo');
-
-my $foo_first_text = $foo_first->footext;
-is($foo_first_text, 'This is the text of the only Foo record associated with the Bar with barid 3');
-
+++ /dev/null
-use strict;
-use Test::More tests => 4;
-use lib qw(t/lib);
-use make_dbictest_db;
-
-eval { require DBD::SQLite };
-my $class = $@ ? 'SQLite2' : 'SQLite';
-
-package DBICTest::Schema;
-use base qw/ DBIx::Class::Schema::Loader /;
-
-__PACKAGE__->loader_options( relationships => 1 );
-__PACKAGE__->connection("dbi:$class:dbname=./t/dbictest.db");
-
-package main;
-
-my $schema_class = 'DBICTest::Schema';
-my $schema = $schema_class->clone;
-isa_ok($schema, 'DBIx::Class::Schema');
-
-my $foo_rs = $schema->resultset('Bar')->search({ barid => 3})->search_related('fooref');
-isa_ok($foo_rs, 'DBIx::Class::ResultSet');
-
-my $foo_first = $foo_rs->first;
-isa_ok($foo_first, 'DBICTest::Schema::Foo');
-
-my $foo_first_text = $foo_first->footext;
-is($foo_first_text, 'This is the text of the only Foo record associated with the Bar with barid 3');
+++ /dev/null
-use strict;
-use Test::More tests => 4;
-use lib qw(t/lib);
-use make_dbictest_db;
-
-eval { require DBD::SQLite };
-my $class = $@ ? 'SQLite2' : 'SQLite';
-
-package DBICTest::Schema;
-use base qw/ DBIx::Class::Schema::Loader /;
-
-__PACKAGE__->loader_options( relationships => 1 );
-
-package main;
-
-my $schema_class = 'DBICTest::Schema';
-my $schema = $schema_class->connect("dbi:$class:dbname=./t/dbictest.db");
-isa_ok($schema, 'DBIx::Class::Schema');
-
-my $foo_rs = $schema->resultset('Bar')->search({ barid => 3})->search_related('fooref');
-isa_ok($foo_rs, 'DBIx::Class::ResultSet');
-
-my $foo_first = $foo_rs->next;
-isa_ok($foo_first, 'DBICTest::Schema::Foo');
-
-my $foo_first_text = $foo_first->footext;
-is($foo_first_text, 'This is the text of the only Foo record associated with the Bar with barid 3');
+++ /dev/null
-use strict;
-use Test::More tests => 4;
-use lib qw(t/lib);
-use make_dbictest_db;
-
-eval { require DBD::SQLite };
-my $class = $@ ? 'SQLite2' : 'SQLite';
-
-package DBICTest::Schema;
-use base qw/ DBIx::Class::Schema::Loader /;
-
-__PACKAGE__->connection("dbi:$class:dbname=./t/dbictest.db");
-__PACKAGE__->loader_options( relationships => 1 );
-
-package main;
-
-my $schema_class = 'DBICTest::Schema';
-my $schema = $schema_class->clone;
-isa_ok($schema, 'DBIx::Class::Schema');
-
-my $foo_rs = $schema->resultset('Bar')->search({ barid => 3})->search_related('fooref');
-isa_ok($foo_rs, 'DBIx::Class::ResultSet');
-
-my $foo_first = $foo_rs->first;
-isa_ok($foo_first, 'DBICTest::Schema::Foo');
-
-my $foo_first_text = $foo_first->footext;
-is($foo_first_text, 'This is the text of the only Foo record associated with the Bar with barid 3');
+++ /dev/null
-use strict;
-use Test::More tests => 4;
-use lib qw(t/lib);
-use make_dbictest_db;
-
-eval { require DBD::SQLite };
-my $class = $@ ? 'SQLite2' : 'SQLite';
-
-use DBIx::Class::Schema::Loader qw/ make_schema_at /;
-
-make_schema_at(
- 'DBICTest::Schema',
- { relationships => 1 },
- [ "dbi:$class:dbname=./t/dbictest.db" ],
-);
-
-my $schema_class = 'DBICTest::Schema';
-my $schema = $schema_class->clone;
-isa_ok($schema, 'DBIx::Class::Schema');
-
-my $foo_rs = $schema->resultset('Bar')->search({ barid => 3})->search_related('fooref');
-isa_ok($foo_rs, 'DBIx::Class::ResultSet');
-
-my $foo_first = $foo_rs->first;
-isa_ok($foo_first, 'DBICTest::Schema::Foo');
-
-my $foo_first_text = $foo_first->footext;
-is($foo_first_text, 'This is the text of the only Foo record associated with the Bar with barid 3');
my $fn = './t/dbictest.db';
unlink($fn);
-
-my $dbh = DBI->connect("dbi:$class:dbname=./t/dbictest.db");
+our $dsn = "dbi:$class:dbname=$fn";
+my $dbh = DBI->connect($dsn);
$dbh->do($_) for (
q|CREATE TABLE foo (
fooref INTEGER REFERENCES foo(fooid)
)|,
q|INSERT INTO foo VALUES (1,'Foo text for number 1')|,
- q|INSERT INTO foo VALUES (2,'This is the text of the only Foo record associated with the Bar with barid 3')|,
+ q|INSERT INTO foo VALUES (2,'Foo record associated with the Bar with barid 3')|,
q|INSERT INTO foo VALUES (3,'Foo text for number 3')|,
q|INSERT INTO foo VALUES (4,'Foo text for number 4')|,
q|INSERT INTO bar VALUES (1,4)|,