fix and regression test for RT #62642
[dbsrgits/DBIx-Class.git] / t / storage / dbh_do.t
CommitLineData
3ff1602f 1use strict;
492bb85a 2use warnings;
3ff1602f 3
492bb85a 4use Test::More;
3ff1602f 5use lib qw(t/lib);
6use DBICTest;
7
8
9my $schema = DBICTest->init_schema();
10my $storage = $schema->storage;
11
492bb85a 12my @args;
13my $test_func = sub { @args = @_ };
3ff1602f 14
492bb85a 15$storage->dbh_do($test_func, "foo", "bar");
16is_deeply (
17 \@args,
18 [ $storage, $storage->dbh, "foo", "bar" ],
3ff1602f 19);
20
492bb85a 21
3ff1602f 22my $storage_class = ref $storage;
23{
492bb85a 24 no strict 'refs';
25 local *{$storage_class .'::__test_method'} = $test_func;
26 $storage->dbh_do("__test_method", "baz", "buz");
3ff1602f 27}
3ff1602f 28
492bb85a 29is_deeply (
30 \@args,
31 [ $storage, $storage->dbh, "baz", "buz" ],
32);
33
38ed54cd 34# test aliasing
35my $res = 'original';
36$storage->dbh_do (sub { $_[2] = 'changed' }, $res);
37
38is ($res, 'changed', "Arguments properly aliased for dbh_do");
39
492bb85a 40done_testing;