5 # This is here because Tie::File is STOOPID.
13 filename => $filename,
21 open( my $fh, $self->{filename} );
31 open( my $fh, $self->{filename} );
41 use Test::More tests => 24;
42 use t::common qw( new_fh );
44 use_ok( 'DBM::Deep' );
46 my ($audit_fh, $audit_file) = new_fh();
49 tie @audit, 'My::Tie::File', $audit_file;
51 my ($fh, $filename) = new_fh();
52 my $db = DBM::Deep->new({
54 audit_file => $audit_file,
57 isa_ok( $db, 'DBM::Deep' );
60 $audit[0], qr/^\# Database created on/,
61 "Audit file header written to",
65 like( $audit[1], qr{^\$db->{foo} = 'bar';}, "Basic assignment correct" );
68 skip 'Not done yet', 20;
70 like( $audit[2], qr{^\$db->{foo} = 'baz';}, "Basic update correct" );
72 $db->{bar} = { a => 1 };
73 like( $audit[3], qr{\$db->\{bar\} = \{\};}, "Hash assignment correct" );
74 like( $audit[4], qr{\$db->\{bar\}\{a\} = '1';}, "... child 1 good" );
76 $db->{baz} = [ 1 .. 2 ];
77 like( $audit[5], qr{\$db->{baz} = \[\];}, "Array assignment correct" );
78 like( $audit[6], qr{\$db->{baz}\[0\] = '1';}, "... child 1 good" );
79 like( $audit[7], qr{\$db->{baz}\[1\] = '2';}, "... child 2 good" );
84 like( $audit[8], qr{\$db->{baz}\[5\] = \[\];}, "Child array assignment correct" );
85 like( $audit[9], qr{\$db->{baz}\[5\]\[0\] = '3';}, "... child 1 good" );
86 like( $audit[10], qr{\$db->{baz}\[5]\[1] = '4';}, "... child 2 good" );
87 like( $audit[11], qr{\$db->{baz}\[5]\[2] = '5';}, "... child 3 good" );
92 $db = DBM::Deep->new({
94 audit_file => $audit_file,
98 like( $audit[12], qr{\$db->{new} = '9';}, "Writing after closing the file works" );
100 my $export = $db->export;
104 my ($fh2, $file2) = new_fh();
105 my $db = DBM::Deep->new({
113 my $export2 = $db->export;
115 is_deeply( $export2, $export, "And recovery works" );
119 $db = DBM::Deep->new({
121 audit_file => $audit_file,
125 like( $audit[13], qr{delete \$db->{baz};}, "Deleting works" );
127 $export = $db->export;
131 my ($fh2, $file2) = new_fh();
132 my $db = DBM::Deep->new({
140 my $export2 = $db->export;
142 is_deeply( $export2, $export, "And recovery works" );
146 $db = DBM::Deep->new({
148 audit_file => $audit_file,
152 like( $audit[14], qr{\$db->{bar} = \{\};}, "Clearing works" );
154 $export = $db->export;
158 my ($fh2, $file2) = new_fh();
159 my $db = DBM::Deep->new({
167 my $export2 = $db->export;
169 is_deeply( $export2, $export, "And recovery works" );
173 $db = DBM::Deep->new({
175 audit_file => $audit_file,
178 $db->{blessed} = bless { a => 5, b => 3 }, 'Floober';
179 like( $audit[15], qr{\$db->{blessed} = bless {}, 'Floober';},
180 "Assignment of a blessed reference works" );
181 like( $audit[16], qr{\$db->{blessed}{a} = '5';}, "... child 1" );
182 like( $audit[17], qr{\$db->{blessed}{b} = '3';}, "... child 2" );
184 $export = $db->export;
188 my ($fh2, $file2) = new_fh();
189 my $db = DBM::Deep->new({
197 my $export2 = $db->export;
199 is_deeply( $export2, $export, "And recovery works" );