Commit | Line | Data |
3ff1602f |
1 | use strict; |
492bb85a |
2 | use warnings; |
3ff1602f |
3 | |
492bb85a |
4 | use Test::More; |
3ff1602f |
5 | use lib qw(t/lib); |
6 | use DBICTest; |
7 | |
8 | |
9 | my $schema = DBICTest->init_schema(); |
10 | my $storage = $schema->storage; |
11 | |
8b60b921 |
12 | $storage = $storage->master |
13 | if $ENV{DBICTEST_VIA_REPLICATED}; |
14 | |
15 | |
8f6986ac |
16 | # test (re)connection |
17 | for my $disconnect (0, 1) { |
18 | $schema->storage->_dbh->disconnect if $disconnect; |
19 | is_deeply ( |
20 | $schema->storage->dbh_do(sub { $_[1]->selectall_arrayref('SELECT 1') }), |
21 | [ [ 1 ] ], |
22 | 'dbh_do on fresh handle worked', |
23 | ); |
24 | } |
25 | |
492bb85a |
26 | my @args; |
27 | my $test_func = sub { @args = @_ }; |
3ff1602f |
28 | |
492bb85a |
29 | $storage->dbh_do($test_func, "foo", "bar"); |
30 | is_deeply ( |
31 | \@args, |
32 | [ $storage, $storage->dbh, "foo", "bar" ], |
3ff1602f |
33 | ); |
34 | |
492bb85a |
35 | |
3ff1602f |
36 | my $storage_class = ref $storage; |
37 | { |
492bb85a |
38 | no strict 'refs'; |
39 | local *{$storage_class .'::__test_method'} = $test_func; |
40 | $storage->dbh_do("__test_method", "baz", "buz"); |
3ff1602f |
41 | } |
3ff1602f |
42 | |
492bb85a |
43 | is_deeply ( |
44 | \@args, |
45 | [ $storage, $storage->dbh, "baz", "buz" ], |
46 | ); |
47 | |
8f6986ac |
48 | # test nested aliasing |
38ed54cd |
49 | my $res = 'original'; |
b74b15b0 |
50 | $schema->storage->dbh_do (sub { |
8f6986ac |
51 | shift->dbh_do(sub { $_[3] = 'changed' }, @_) |
52 | }, $res); |
38ed54cd |
53 | |
54 | is ($res, 'changed', "Arguments properly aliased for dbh_do"); |
55 | |
492bb85a |
56 | done_testing; |