line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Class::PObject::Driver::db_file; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
# $Id: db_file.pm,v 1.5 2003/11/07 04:43:14 sherzodr Exp $ |
4
|
|
|
|
|
|
|
|
5
|
1
|
|
|
1
|
|
3
|
use strict; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
34
|
|
6
|
|
|
|
|
|
|
#use diagnostics; |
7
|
1
|
|
|
1
|
|
3
|
use vars ('$VERSION', '@ISA'); |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
45
|
|
8
|
1
|
|
|
1
|
|
4
|
use Carp; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
48
|
|
9
|
1
|
|
|
1
|
|
181
|
use DB_File; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
use Class::PObject::Driver::DBM; |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
@ISA = ('Class::PObject::Driver::DBM'); |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
$VERSION = '2.01'; |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
sub dbh { |
17
|
|
|
|
|
|
|
my ($self, $object_name, $props, $lock_type) = @_; |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
my $filename = $self->_filename($object_name, $props); |
20
|
|
|
|
|
|
|
my ($DB, %dbh, $unlock); |
21
|
|
|
|
|
|
|
$unlock = $self->_lock($filename, $lock_type||'r') or return undef; |
22
|
|
|
|
|
|
|
unless ( $DB = tie %dbh, "DB_File", $filename, O_RDWR|O_CREAT, 0600 ) { |
23
|
|
|
|
|
|
|
$self->errstr("couldn't connect to '$filename': $!"); |
24
|
|
|
|
|
|
|
return undef |
25
|
|
|
|
|
|
|
} |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
return ($DB, \%dbh, $unlock) |
28
|
|
|
|
|
|
|
} |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
sub drop_datasource { |
34
|
|
|
|
|
|
|
my ($self, $object_name, $props) = @_; |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
my (undef, $dbh, $unlock) = $self->dbh($object_name, $props, 'w') or return; |
37
|
|
|
|
|
|
|
my $filename = $self->_filename($object_name, $props); |
38
|
|
|
|
|
|
|
unless ( unlink $filename ) { |
39
|
|
|
|
|
|
|
$self->errstr( "couldn't unlink '$filename': $!" ); |
40
|
|
|
|
|
|
|
return undef |
41
|
|
|
|
|
|
|
} |
42
|
|
|
|
|
|
|
$unlock->(); |
43
|
|
|
|
|
|
|
return 1 |
44
|
|
|
|
|
|
|
} |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
sub _filename { |
51
|
|
|
|
|
|
|
my ($self, $object_name, $props) = @_; |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
my $dir = $self->_dir($props); |
55
|
|
|
|
|
|
|
my $filename = lc $object_name; |
56
|
|
|
|
|
|
|
$filename =~ s/\W+/_/g; |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
return File::Spec->catfile($dir, $filename . '.dbm') |
59
|
|
|
|
|
|
|
} |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
sub _dir { |
64
|
|
|
|
|
|
|
my ($self, $props) = @_; |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
my $dir = $props->{datasource} || File::Spec->tmpdir(); |
67
|
|
|
|
|
|
|
unless ( -e $dir ) { |
68
|
|
|
|
|
|
|
require File::Path; |
69
|
|
|
|
|
|
|
File::Path::mkpath($dir) or die $! |
70
|
|
|
|
|
|
|
} |
71
|
|
|
|
|
|
|
return $dir |
72
|
|
|
|
|
|
|
} |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
1; |
77
|
|
|
|
|
|
|
__END__ |