sub _maybe_attach_source_to_schema {
my ($class, $source) = @_;
if (my $meth = $class->can('schema_instance')) {
- my $schema = $class->$meth;
- $schema->register_class($class, $class);
- my $new_source = $schema->source($class);
- %$source = %$new_source;
- $schema->source_registrations->{$class} = $source;
+ if (my $schema = $class->$meth) {
+ $schema->register_class($class, $class);
+ my $new_source = $schema->source($class);
+ %$source = %$new_source;
+ $schema->source_registrations->{$class} = $source;
+ }
}
}
sub search_like {
my $class = shift;
- carp "search_like() is deprecated and will be removed in 0.09. Use search() instead.";
+ carp join ("\n",
+ 'search_like() is deprecated and will be removed in 0.09.',
+ 'Instead use ->search({ x => { -like => "y%" } })',
+ '(note the outer pair of {}s - they are important!)'
+ );
my $attrs = (@_ > 1 && ref $_[$#_] eq 'HASH' ? pop(@_) : {});
my $query = ref $_[0] eq 'HASH' ? { %{shift()} }: {@_};
$query->{$_} = { 'like' => $query->{$_} } for keys %$query;
# Multi-column search
{
- my @films = $blrunner->search_like(title => "Bladerunner%", rating => '15');
+ my @films = $blrunner->search (title => { -like => "Bladerunner%"}, rating => '15');
is @films, 1, "Only one Bladerunner is a 15";
}
is($films[0]->id, $gone->id, ' ... the correct one');
# Find all films which were directed by Bob
-@films = Film->search_like('Director', 'Bob %');
+@films = Film->search ( { 'Director' => { -like => 'Bob %' } });
is(scalar @films, 3, ' search_like returns 3 films');
ok(
eq_array(
sub Class::DBI::sheep { ok 0; }
}
+# Install the deprecation warning intercept here for the rest of the 08 dev cycle
+local $SIG{__WARN__} = sub {
+ warn @_ unless (DBIx::Class->VERSION < 0.09 and $_[0] =~ /Query returned more than one row/);
+};
+
sub Film::mutator_name {
my ($class, $col) = @_;
return "set_sheep" if lc $col eq "numexplodingsheep";
like $@, qr/film/, "no hasa film";
eval {
- local $SIG{__WARN__} = sub {
- warn @_ unless $_[0] =~ /Query returned more than one row/;
- };
ok my $f = $ac->movie, "hasa movie";
isa_ok $f, "Film";
is $f->id, $bt->id, " - Bad Taste";
my $abigail = eval { Film->create({ title => "Abigail's Party" }) };
like $@, qr/read only/, "Or create new films";
- $sandl->discard_changes;
+ $_->discard_changes for ($naked, $sandl);
}
eval { require Time::Piece::MySQL };
plan skip_all => "Need Time::Piece::MySQL for this test" if $@;
+use lib 't/cdbi/testlib';
eval { require 't/cdbi/testlib/Log.pm' };
plan skip_all => "Need MySQL for this test" if $@;
use vars qw/$dbh/;
-# temporary, might get switched to the new test framework someday
-my @connect = ("dbi:mysql:test", "", "", { PrintError => 0});
-
+my @connect = (@ENV{map { "DBICTEST_MYSQL_${_}" } qw/DSN USER PASS/}, { PrintError => 0});
$dbh = DBI->connect(@connect) or die DBI->errstr;
my @table;