DiaColloDB/Temp/Array.pm untested

filter: Statementstmt 0.0% 0 / 15 Branchbran 0.0% 0 / 6 Conditioncond 0.0% 0 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 0.0% 0 / 5 Podpod 0.0% 0 / 2 totaltotal 0.0% 0 / 33 CC 4 SCAR 19.1
CC
4
Cov
0%
TIEARRAY
12.0
cleanup
6.0
BEGIN
2.0
CRAP 6.8
1 ## -*- Mode: CPerl -*-
2 ## File: DiaColloDB::Temp::Array.pm
3 ## Author: Bryan Jurish <moocow@cpan.org>
4 ## Description: DiaColloDB: temporary arrays
5  
6 package DiaColloDB::Temp::Array;
7 use DiaColloDB::Temp;
8 use Tie::File::Indexed::JSON;
9 use strict;
10  
11 ##======================================================================
12 ## Globals
13 our @ISA = qw(Tie::File::Indexed::JSON DiaColloDB::Temp);
14  
15 ##======================================================================
16 ## DiaColloDB::Temp API
17  
18 ## $tied = TIEARRAY($classname, $filename, %opts)
19 ## + honors 'UNLINK' option in %opts to auto-unlink $filename on object destruction
20 ## + honors 'APPEND' option in %opts to append to a pre-existing file
21 sub TIEARRAY {
22 my ($that,$file,%opts) = @_;
23 return $that->SUPER::TIEARRAY($file,
24 #%opts,
25 mode=>('rw'.($opts{APPEND} ? 'a' : '')),
26 temp=>(!exists($opts{UNLINK}) || $opts{UNLINK}),
27 (map {exists($opts{$_}) ? ($_=>$opts{$_}) : qw()} qw(pack_o pack_l)),
28 );
29 }
30  
31 ## undef = $obj->cleanup()
32 ## + unlink temp files (only if created with 'UNLINK' option)
33 sub cleanup {
34 $_[0]->unlink() if ($_[0]{temp});
35 }
36  
37  
38 1; ##-- be happy
39  
40 __END__