10 package DBICTest::ExplodingStorage::Sth;
14 sub execute { die "Kablammo!" }
18 package DBICTest::ExplodingStorage;
21 use base 'DBIx::Class::Storage::DBI::SQLite';
25 my ($self, $sql) = @_;
26 return bless {}, "DBICTest::ExplodingStorage::Sth" unless $count++;
27 return $self->next::method($sql);
31 return 0 if $count == 1;
32 return shift->next::method(@_);
38 my $schema = DBICTest->init_schema( sqlite_use_file => 1 );
40 is( ref($schema->storage), 'DBIx::Class::Storage::DBI::SQLite',
41 'Storage reblessed correctly into DBIx::Class::Storage::DBI::SQLite' );
43 my $storage = $schema->storage;
44 $storage->ensure_connected;
47 $schema->storage->throw_exception('test_exception_42');
49 like($@, qr/\btest_exception_42\b/, 'basic exception');
52 $schema->resultset('CD')->search_literal('broken +%$#$1')->all;
54 like($@, qr/prepare_cached failed/, 'exception via DBI->HandleError, etc');
56 bless $storage, "DBICTest::ExplodingStorage";
57 $schema->storage($storage);
60 $schema->resultset('Artist')->create({ name => "Exploding Sheep" });
63 is($@, "", "Exploding \$sth->execute was caught");
65 is(1, $schema->resultset('Artist')->search({name => "Exploding Sheep" })->count,
66 "And the STH was retired");
69 # testing various invocations of connect_info ([ ... ])
71 my $coderef = sub { 42 };
73 'connect_info ([ $d, $u, $p, \%attr, \%extra_attr])' => {
79 on_connect_do => [qw/a b c/],
84 on_disconnect_do => [qw/d e f/],
102 'connect_info ([ \%code, \%extra_attr ])' => {
106 on_connect_do => [qw/a b c/],
109 on_disconnect_do => [qw/d e f/],
116 dbi_connect_info => [
121 'connect_info ([ \%attr ])' => {
124 on_connect_do => [qw/a b c/],
127 on_disconnect_do => [qw/d e f/],
136 dbi_connect_info => [
148 for my $type (keys %$invocations) {
150 # we can not use a cloner portably because of the coderef
151 # so compare dumps instead
152 local $Data::Dumper::Sortkeys = 1;
153 my $arg_dump = Dumper ($invocations->{$type}{args});
155 $storage->connect_info ($invocations->{$type}{args});
157 is ($arg_dump, Dumper ($invocations->{$type}{args}), "$type didn't modify passed arguments");
160 is_deeply ($storage->_dbi_connect_info, $invocations->{$type}{dbi_connect_info}, "$type produced correct _dbi_connect_info");
161 ok ( (not $storage->auto_savepoint and not $storage->unsafe), "$type correctly ignored extra hashref");
164 [$storage->on_connect_do, $storage->on_disconnect_do ],
165 [ [qw/a b c/], [qw/d e f/] ],
166 "$type correctly parsed DBIC specific on_[dis]connect_do",