From: Peter Rabbitson Date: Sun, 17 Jul 2011 19:08:49 +0000 (-0400) Subject: Fix last test susceptible to spurious warnings, cleanup a bit X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=e42bbd7fdce08d85476fec5bcf6971ddcc401955;p=dbsrgits%2FDBIx-Class-Historic.git Fix last test susceptible to spurious warnings, cleanup a bit --- diff --git a/lib/DBIx/Class/Schema.pm b/lib/DBIx/Class/Schema.pm index 033c0b7..1959f40 100644 --- a/lib/DBIx/Class/Schema.pm +++ b/lib/DBIx/Class/Schema.pm @@ -1479,55 +1479,51 @@ more information. =cut -{ - my $warn; - - sub compose_connection { - my ($self, $target, @info) = @_; - - carp "compose_connection deprecated as of 0.08000" - unless ($INC{"DBIx/Class/CDBICompat.pm"} || $warn++); +sub compose_connection { + my ($self, $target, @info) = @_; - my $base = 'DBIx::Class::ResultSetProxy'; - try { - eval "require ${base};" - } - catch { - $self->throw_exception - ("No arguments to load_classes and couldn't load ${base} ($_)") - }; - - if ($self eq $target) { - # Pathological case, largely caused by the docs on early C::M::DBIC::Plain - foreach my $moniker ($self->sources) { - my $source = $self->source($moniker); - my $class = $source->result_class; - $self->inject_base($class, $base); - $class->mk_classdata(resultset_instance => $source->resultset); - $class->mk_classdata(class_resolver => $self); - } - $self->connection(@info); - return $self; - } + carp_once "compose_connection deprecated as of 0.08000" + unless $INC{"DBIx/Class/CDBICompat.pm"}; - my $schema = $self->compose_namespace($target, $base); - { - no strict 'refs'; - my $name = join '::', $target, 'schema'; - *$name = subname $name, sub { $schema }; - } + my $base = 'DBIx::Class::ResultSetProxy'; + try { + eval "require ${base};" + } + catch { + $self->throw_exception + ("No arguments to load_classes and couldn't load ${base} ($_)") + }; - $schema->connection(@info); - foreach my $moniker ($schema->sources) { - my $source = $schema->source($moniker); + if ($self eq $target) { + # Pathological case, largely caused by the docs on early C::M::DBIC::Plain + foreach my $moniker ($self->sources) { + my $source = $self->source($moniker); my $class = $source->result_class; - #warn "$moniker $class $source ".$source->storage; - $class->mk_classdata(result_source_instance => $source); + $self->inject_base($class, $base); $class->mk_classdata(resultset_instance => $source->resultset); - $class->mk_classdata(class_resolver => $schema); + $class->mk_classdata(class_resolver => $self); } - return $schema; + $self->connection(@info); + return $self; + } + + my $schema = $self->compose_namespace($target, $base); + { + no strict 'refs'; + my $name = join '::', $target, 'schema'; + *$name = subname $name, sub { $schema }; } + + $schema->connection(@info); + foreach my $moniker ($schema->sources) { + my $source = $schema->source($moniker); + my $class = $source->result_class; + #warn "$moniker $class $source ".$source->storage; + $class->mk_classdata(result_source_instance => $source); + $class->mk_classdata(resultset_instance => $source->resultset); + $class->mk_classdata(class_resolver => $schema); + } + return $schema; } 1; diff --git a/t/30dbicplain.t b/t/30dbicplain.t deleted file mode 100644 index 736380e..0000000 --- a/t/30dbicplain.t +++ /dev/null @@ -1,18 +0,0 @@ -use strict; -use warnings; -use Test::More; -use Test::Warn; - -use lib qw(t/lib); - -warnings_like { require DBICTest::Plain } - [ - qr/compose_connection deprecated as of 0\.08000/, - qr/\QDBIx::Class::ResultSetProxy is DEPRECATED/, - ], - 'no unexpected warnings' -; - -cmp_ok(DBICTest::Plain->resultset('Test')->count, '>', 0, 'count is valid'); - -done_testing; \ No newline at end of file diff --git a/t/40compose_connection.t b/t/40compose_connection.t new file mode 100644 index 0000000..051ab9b --- /dev/null +++ b/t/40compose_connection.t @@ -0,0 +1,19 @@ +use strict; +use warnings; +use Test::More; +use Test::Warn; + +use lib qw(t/lib); +use DBICTest; + +warnings_exist { DBICTest->init_schema( compose_connection => 1, sqlite_use_file => 1 ) } + [ + qr/compose_connection deprecated as of 0\.08000/, + qr/\QDBIx::Class::ResultSetProxy is DEPRECATED/, + ], + 'got expected deprecation warnings' +; + +cmp_ok(DBICTest->resultset('Artist')->count, '>', 0, 'count is valid'); + +done_testing; diff --git a/t/40resultsetmanager.t b/t/40resultsetmanager.t index 2ac44eb..45c6e3e 100644 --- a/t/40resultsetmanager.t +++ b/t/40resultsetmanager.t @@ -1,15 +1,16 @@ use strict; use warnings; use Test::More; +use Test::Warn; use lib qw(t/lib); -BEGIN { - local $SIG{__WARN__} = sub {}; - require DBIx::Class::ResultSetManager; -} - -use DBICTest::ResultSetManager; +warnings_exist { require DBICTest::ResultSetManager } + [ + qr/\QDBIx::Class::ResultSetManager never left experimental status/, + ], + 'found deprecation warning' +; my $schema = DBICTest::ResultSetManager->compose_namespace('DB'); my $rs = $schema->resultset('Foo'); diff --git a/t/lib/DBICTest/Plain.pm b/t/lib/DBICTest/Plain.pm deleted file mode 100644 index 209cc3e..0000000 --- a/t/lib/DBICTest/Plain.pm +++ /dev/null @@ -1,40 +0,0 @@ -package # hide from PAUSE - DBICTest::Plain; - -use strict; -use warnings; -use base qw/DBIx::Class::Schema/; -use DBI; - -my $db_file = "t/var/Plain.db"; - -unlink($db_file) if -e $db_file; -unlink($db_file . "-journal") if -e $db_file . "-journal"; -mkdir("t/var") unless -d "t/var"; - -my $dsn = "dbi:SQLite:${db_file}"; - -__PACKAGE__->load_classes("Test"); -my $schema = __PACKAGE__->compose_connection( - __PACKAGE__, - $dsn, - undef, - undef, - { AutoCommit => 1 } -); - -my $dbh = DBI->connect($dsn); - -my $sql = <do($_) for split(/\n\n/, $sql); - -1; diff --git a/t/lib/DBICTest/Plain/Test.pm b/t/lib/DBICTest/Plain/Test.pm deleted file mode 100644 index e950278..0000000 --- a/t/lib/DBICTest/Plain/Test.pm +++ /dev/null @@ -1,18 +0,0 @@ -package # hide from PAUSE - DBICTest::Plain::Test; - -use base 'DBIx::Class::Core'; - -__PACKAGE__->table('test'); -__PACKAGE__->add_columns( - 'id' => { - data_type => 'integer', - is_auto_increment => 1 - }, - 'name' => { - data_type => 'varchar', - }, -); -__PACKAGE__->set_primary_key('id'); - -1;