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 );
32 my $FileHandle = new FileHandle;
34 sub ParseVersion1Record
37 my @fields = ( "originator", "date", "subject", "msgid", "package",
38 "keywords", "done", "forwarded", "mergedwith", "severity" );
42 print "D2: (DBase) Record Fields:\n" if $Globals{ 'debug' } > 1;
43 foreach my $line ( @data )
47 $Record{ $tag } = $line;
48 print "\t $tag = $line\n" if $Globals{ 'debug' } > 1;
50 $GTags{ "BUG_$tag" } = $line;
54 sub ParseVersion2Record
56 # I envision the next round of records being totally different in
57 # meaning. In order to maintain compatability, version tagging will be
58 # implemented in thenext go around and different versions will be sent
59 # off to different functions to be parsed and interpreted into a format
60 # that the rest of the system will understand. All data will be saved
61 # in whatever 'new" format ixists. The difference will be a "Version: x"
62 # at the top of the file.
64 print "No version 2 records are understood at this time\n";
71 print "V: Reading $record\n" if $Globals{ 'verbose' };
72 if ( $record ne $LoadedRecord )
77 print "D1: (DBase) $record is being loaded\n" if $Globals{ 'debug' };
79 #find proper directory to store in
80 #later, this will be for tree'd data directory the way
82 $path = "/db/".$record.".status";
83 print "D2: (DBase) $path found as data path\n" if $Globals{ 'debug' } > 1;
85 open( $FileHandle, $Globals{ "work-dir" } . $path )
86 || &fail( "Unable to open record: ".$Globals{ "work-dir" }."$path\n");
87 flock( $FileHandle, LOCK_EX ) || &fail( "Unable to lock record $record\n" );
88 @data = <$FileHandle>;
89 if ( scalar( @data ) =~ /Version: (\d*)/ )
92 { &ParseVersion2Record( @data ); }
94 { &fail( "Unknown record version: $1\n"); }
96 else { &ParseVersion1Record( @data ); }
97 $LoadedRecord = $record;
99 else { print "D1: (DBase) $record is already loaded\n" if $Globals{ 'debug' }; }
105 my @fields = ( "originator", "date", "subject", "msgid", "package",
106 "keywords", "done", "forwarded", "mergedwith", "severity" );
107 seek( $FileHandle, 0, 0 );
108 for( my $i = 0; $i < $#fields; $i++ )
110 if ( defined( $fields[$i] ) )
111 { print $FileHandle $Record{ $fields[$i] } . "\n"; }
112 else { print $FileHandle "\n"; }
120 END { } # module clean-up code here (global destructor)