Commit | Line | Data |
3705e3b2 |
1 | use warnings; |
2 | use strict; |
3 | |
4 | use Test::More; |
5 | use Test::Warn; |
6 | |
7 | use lib qw(t/lib); |
8 | use DBICTest; |
9 | |
10 | use DBIx::Class::_Util 'is_plain_value'; |
11 | |
12 | { |
13 | package # hideee |
14 | DBICTest::SillyInt; |
15 | |
16 | use overload |
17 | # *DELIBERATELY* unspecified |
18 | #fallback => 1, |
19 | '0+' => sub { ${$_[0]} }, |
20 | ; |
21 | |
22 | |
23 | package # hideee |
24 | DBICTest::SillyInt::Subclass; |
25 | |
26 | our @ISA = 'DBICTest::SillyInt'; |
27 | |
28 | |
29 | package # hideee |
30 | DBICTest::CrazyInt; |
31 | |
32 | use overload |
33 | '0+' => sub { 666 }, |
34 | '""' => sub { 999 }, |
35 | fallback => 1, |
36 | ; |
37 | } |
38 | |
39 | # check DBI behavior when fed a stringifiable/nummifiable value |
40 | { |
41 | my $crazynum = bless {}, 'DBICTest::CrazyInt'; |
42 | cmp_ok( $crazynum, '==', 666 ); |
43 | cmp_ok( $crazynum, 'eq', 999 ); |
44 | |
45 | my $schema = DBICTest->init_schema( no_populate => 1 ); |
46 | $schema->storage->dbh_do(sub { |
47 | $_[1]->do('INSERT INTO artist (name) VALUES (?)', {}, $crazynum ); |
48 | }); |
49 | |
50 | is( $schema->resultset('Artist')->next->name, 999, 'DBI preferred stringified version' ); |
51 | } |
52 | |
53 | # make sure we recognize overloaded stuff properly |
54 | { |
55 | my $num = bless( \do { my $foo = 69 }, 'DBICTest::SillyInt::Subclass' ); |
56 | ok( is_plain_value $num, 'parent-fallback-provided stringification detected' ); |
57 | is("$num", 69, 'test overloaded object stringifies, without specified fallback'); |
58 | } |
59 | |
60 | done_testing; |