Converted all relevant tests to use new_dbm instead of new_fh and all tests (except...
[dbsrgits/DBM-Deep.git] / t / 30_already_tied.t
1 use strict;
2 use warnings FATAL => 'all';
3
4 use Test::More;
5 use Test::Exception;
6 use t::common qw( new_dbm );
7
8 use_ok( 'DBM::Deep' );
9
10 my $dbm_factory = new_dbm();
11 while ( my $dbm_maker = $dbm_factory->() ) {
12     my $db = $dbm_maker->();
13
14     {
15         {
16             package My::Tie::Hash;
17
18             sub TIEHASH {
19                 my $class = shift;
20
21                 return bless {
22                 }, $class;
23             }
24         }
25
26         my %hash;
27         tie %hash, 'My::Tie::Hash';
28         isa_ok( tied(%hash), 'My::Tie::Hash' );
29
30         throws_ok {
31             $db->{foo} = \%hash;
32         } qr/Cannot store something that is tied/, "Cannot store tied hashes";
33     }
34
35     {
36         {
37             package My::Tie::Array;
38
39             sub TIEARRAY {
40                 my $class = shift;
41
42                 return bless {
43                 }, $class;
44             }
45
46             sub FETCHSIZE { 0 }
47         }
48
49         my @array;
50         tie @array, 'My::Tie::Array';
51         isa_ok( tied(@array), 'My::Tie::Array' );
52
53         throws_ok {
54             $db->{foo} = \@array;
55         } qr/Cannot store something that is tied/, "Cannot store tied arrays";
56     }
57
58     {
59         {
60             package My::Tie::Scalar;
61
62             sub TIESCALAR {
63                 my $class = shift;
64
65                 return bless {
66                 }, $class;
67             }
68         }
69
70         my $scalar;
71         tie $scalar, 'My::Tie::Scalar';
72         isa_ok( tied($scalar), 'My::Tie::Scalar' );
73
74         throws_ok {
75             $db->{foo} = \$scalar;
76         } qr/Storage of references of type 'SCALAR' is not supported/, "Cannot store scalar references, let alone tied scalars";
77     }
78 }
79
80 done_testing;