1 package Debbugs::DBase; # assumes Some/Module.pm
7 use vars qw($VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS);
9 # set the version for version checking
13 @EXPORT = qw( %Record );
14 %EXPORT_TAGS = ( ); # eg: TAG => [ qw!name1 name2! ],
16 # your exported package globals go here,
17 # as well as any optionally exported functions
18 @EXPORT_OK = qw( %Record );
23 use Debbugs::Config qw(%Globals);
31 my $FileHandle = new FileHandle;
33 sub ParseVersion1Record
36 my @fields = ( "originator", "date", "subject", "msgid", "package",
37 "keywords", "done", "forwarded", "mergedwith", "severity" );
39 foreach my $line ( @data )
42 $Record{ $fields[$i] } = $line;
47 sub ParseVersion2Record
49 # I envision the next round of records being totally different in
50 # meaning. In order to maintain compatability, version tagging will be
51 # implemented in thenext go around and different versions will be sent
52 # off to different functions to be parsed and interpreted into a format
53 # that the rest of the system will understand. All data will be saved
54 # in whatever 'new" format ixists. The difference will be a "Version: x"
55 # at the top of the file.
57 print "No version 2 records are understood at this time\n";
64 if ( $record ne $LoadedRecord )
69 #find proper directory to store in
70 #later, this will be for tree'd data directory the way
72 $path = "/db/".$record.".status";
74 open( $FileHandle, $Globals{ "work-dir" } . $path )
75 || &fail( "Unable to open record: ".$Globals{ "work-dir" }."$path\n");
76 flock( $FileHandle, LOCK_EX ) || &fail( "Unable to lock record $record\n" );
77 @data = <$FileHandle>;
78 if ( scalar( @data ) =~ /Version: (\d*)/ )
81 { &ParseVersion2Record( @data ); }
83 { &fail( "Unknown record version: $1\n"); }
85 else { &ParseVersion1Record( @data ); }
86 $LoadedRecord = $record;
93 my @fields = ( "originator", "date", "subject", "msgid", "package",
94 "keywords", "done", "forwarded", "mergedwith", "severity" );
95 seek( $FileHandle, 0, 0 );
96 for( my $i = 0; $i < $#fields; $i++ )
98 if ( defined( $fields[$i] ) )
99 { print $FileHandle $Record{ $fields[$i] } . "\n"; }
100 else { print $FileHandle "\n"; }
108 END { } # module clean-up code here (global destructor)