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 | |
8f6986ac |
12 | # test (re)connection |
13 | for my $disconnect (0, 1) { |
14 | $schema->storage->_dbh->disconnect if $disconnect; |
15 | is_deeply ( |
16 | $schema->storage->dbh_do(sub { $_[1]->selectall_arrayref('SELECT 1') }), |
17 | [ [ 1 ] ], |
18 | 'dbh_do on fresh handle worked', |
19 | ); |
20 | } |
21 | |
492bb85a |
22 | my @args; |
23 | my $test_func = sub { @args = @_ }; |
3ff1602f |
24 | |
492bb85a |
25 | $storage->dbh_do($test_func, "foo", "bar"); |
26 | is_deeply ( |
27 | \@args, |
28 | [ $storage, $storage->dbh, "foo", "bar" ], |
3ff1602f |
29 | ); |
30 | |
492bb85a |
31 | |
3ff1602f |
32 | my $storage_class = ref $storage; |
33 | { |
492bb85a |
34 | no strict 'refs'; |
35 | local *{$storage_class .'::__test_method'} = $test_func; |
36 | $storage->dbh_do("__test_method", "baz", "buz"); |
3ff1602f |
37 | } |
3ff1602f |
38 | |
492bb85a |
39 | is_deeply ( |
40 | \@args, |
41 | [ $storage, $storage->dbh, "baz", "buz" ], |
42 | ); |
43 | |
8f6986ac |
44 | # test nested aliasing |
38ed54cd |
45 | my $res = 'original'; |
8f6986ac |
46 | $storage->dbh_do (sub { |
47 | shift->dbh_do(sub { $_[3] = 'changed' }, @_) |
48 | }, $res); |
38ed54cd |
49 | |
50 | is ($res, 'changed', "Arguments properly aliased for dbh_do"); |
51 | |
492bb85a |
52 | done_testing; |