Commit | Line | Data |
b5ce6748 |
1 | use warnings; |
2 | use strict; |
3 | |
4 | use Test::More; |
5 | |
6 | use lib qw(t/lib); |
7 | use DBICTest; |
8 | |
9 | { |
10 | package # hideee |
11 | DBICTest::CrazyInt; |
12 | |
13 | use overload |
14 | '0+' => sub { 666 }, |
15 | '""' => sub { 999 }, |
16 | fallback => 1, |
17 | ; |
18 | } |
19 | |
20 | # check DBI behavior when fed a stringifiable/nummifiable value |
21 | { |
22 | my $crazynum = bless {}, 'DBICTest::CrazyInt'; |
23 | cmp_ok( $crazynum, '==', 666 ); |
24 | cmp_ok( $crazynum, 'eq', 999 ); |
25 | |
26 | my $schema = DBICTest->init_schema( no_populate => 1 ); |
27 | $schema->storage->dbh_do(sub { |
28 | $_[1]->do('INSERT INTO artist (name) VALUES (?)', {}, $crazynum ); |
29 | }); |
30 | |
31 | is( $schema->resultset('Artist')->next->name, 999, 'DBI preferred stringified version' ); |
32 | } |
33 | done_testing; |