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