blob: 87d4ba02f20e12ef0cbf4ee6f1a83fd064fbd19c (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
|
#-*- perl -*-
#
# Copyright (C) 2001 Ken'ichi Fukamachi
# All rights reserved. This program is free software; you can
# redistribute it and/or modify it under the same terms as Perl itself.
#
# $FML: @template.pm,v 1.1 2001/08/07 12:23:48 fukachan Exp $
#
package Mail::ThreadTrack::DB;
use strict;
use vars qw(@ISA @EXPORT @EXPORT_OK $AUTOLOAD);
use Carp;
=head1 NAME
Mail::ThreadTrack::DB - what is this
=head1 SYNOPSIS
=head1 DESCRIPTION
=head1 METHODS
=cut
=head2 C<db_open()>
open DB.
It uses tie() to bind a hash to a DB file.
Our minimal_states uses several DB files for
C<%ticket_id>,
C<%date>,
C<%status>,
C<%sender>,
C<%articles>,
C<%message_id>
and
C<%index>.
=head2 C<db_close()>
untie() corresponding hashes opened by C<db_open()>.
=cut
my @kind_of_databases = qw(ticket_id
info
date
status
sender
articles
message_id
index);
sub db_open
{
my ($self) = @_;
my $db_type = $self->{ config }->{ ticket_db_type } || 'AnyDBM_File';
my $db_dir = $self->{ _db_dir };
my $index_file = $self->{ _index_db };
eval qq{ use $db_type; use Fcntl;};
unless ($@) {
for my $db (@kind_of_databases) {
my $file = "$db_dir/${db}";
my $str = qq{
my \%$db = ();
tie \%$db, \$db_type, \$file, O_RDWR|O_CREAT, 0644;
\$self->{ _hash_table }->{ _$db } = \\\%$db;
};
eval $str;
croak($@) if $@;
}
}
else {
croak("cannot use $db_type");
}
1;
}
sub db_close
{
my ($self) = @_;
for my $db (@kind_of_databases) {
my $str = qq{
my \$${db} = \$self->{ _hash_table }->{ _$db };
untie \%\$${db};
};
eval $str;
croak($@) if $@;
}
}
=head1 AUTHOR
Ken'ichi Fukamachi
=head1 COPYRIGHT
Copyright (C) 2001 Ken'ichi Fukamachi
All rights reserved. This program is free software; you can
redistribute it and/or modify it under the same terms as Perl itself.
=head1 HISTORY
Mail::ThreadTrack::DB appeared in fml5 mailing list driver package.
See C<http://www.fml.org/> for more details.
=cut
1;
|