Added guard to make sure values that cannot be read correctly aren't stored, plus...
[dbsrgits/DBM-Deep.git] / t / 26_scalar_ref.t
CommitLineData
a8026397 1use strict;
2
eea0d863 3use Test::More tests => 10;
4use Test::Exception;
2a81bf9e 5use File::Temp qw( tempfile tempdir );
a8026397 6
7use_ok( 'DBM::Deep' );
8
2a81bf9e 9my $dir = tempdir( CLEANUP => 1 );
10my ($fh, $filename) = tempfile( 'tmpXXXX', UNLINK => 1, DIR => $dir );
11
eea0d863 12my $x = 25;
a8026397 13{
2a81bf9e 14 my $db = DBM::Deep->new( $filename );
a8026397 15
eea0d863 16 throws_ok {
17 $db->{scalarref} = \$x;
18 } qr/Storage of variables of type 'SCALAR' is not supported/,
19 'Storage of scalar refs not supported';
a8026397 20
eea0d863 21 throws_ok {
22 $db->{scalarref} = \\$x;
23 } qr/Storage of variables of type 'REF' is not supported/,
24 'Storage of ref refs not supported';
25
26 throws_ok {
27 $db->{scalarref} = sub { 1 };
28 } qr/Storage of variables of type 'CODE' is not supported/,
29 'Storage of code refs not supported';
30
31 throws_ok {
32 $db->{scalarref} = $db->_get_self->_fh;
33 } qr/Storage of variables of type 'GLOB' is not supported/,
34 'Storage of glob refs not supported';
35
36 $db->{scalar} = $x;
a8026397 37 TODO: {
eea0d863 38 todo_skip "Refs to DBM::Deep objects aren't implemented yet", 2;
39 lives_ok {
40 $db->{selfref} = \$db->{scalar};
41 } "Refs to DBM::Deep objects are ok";
42
43 is( ${$db->{selfref}}, $x, "A ref to a DBM::Deep object is ok" );
a8026397 44 }
45}
46
47{
2a81bf9e 48 my $db = DBM::Deep->new( $filename );
a8026397 49
a8026397 50 is( $db->{scalar}, $x, "Scalar retrieved ok" );
51 TODO: {
eea0d863 52 todo_skip "Refs to DBM::Deep objects aren't implemented yet", 2;
a8026397 53 is( ${$db->{scalarref}}, 30, "Scalarref retrieved ok" );
eea0d863 54 is( ${$db->{selfref}}, 26, "Scalarref to stored scalar retrieved ok" );
a8026397 55 }
56}